C: typedef union

35,097

uint8_t is located in stdint.h, not in ctype.h (nor ctypes.h, no such header exists). You must use a compiler that follows a newer version of the C standard for this header to be found (C99 or C11 standards).

Share:
35,097
dccharacter
Author by

dccharacter

Updated on February 06, 2020

Comments

  • dccharacter
    dccharacter over 4 years

    didn't find anything in related questions. Most probably it's super noob, but I'll ask anyway/ I've got the following in my .h file:

    typedef union _API_Packet_0x90{
        uint8_t packet[26];
        struct _pack_struct {
            uint8_t start;
            uint8_t length[2];
            uint8_t addr64[8];
            uint8_t addr16[2];
            uint8_t options;
            uint8_t rfData[4];
            uint8_t chksum;
        };
    } API_Packet_0x90;
    
    API_Packet_0x90 ap90;
    

    This is code for a microcontroller, I'm using xc8 toolchain (former Hi Tech C). The compiler says:

    xbee_api.h:19: warning: missing basic type; int assumed
    xbee_api.h:19: error: ";" expected
    xbee_api.h:19: warning: missing basic type; int assumed
    xbee_api.h:21: warning: missing basic type; int assumed

    , and this goes on (too many errors)

    I thought it's uint8_t, so I added #include <ctypes.h>. Nope. I thought it is about names, so I tried all kinds of plays such as

    typedef union {
        uint8_t packet[26];
        struct _pack_struct {
    
        };
    } API_Packet_0x90;
    

    or

    typedef union {
        uint8_t packet[];
        struct _pack_struct {
    
        };
    } API_Packet_0x90;
    

    or others. Nothing helps. I'm stuck as I believe I'm following syntax properly. Any help?

  • dccharacter
    dccharacter over 11 years
    I thought it was a super-stupid mistake. That was it. Thank you.
  • old_timer
    old_timer over 11 years
    Or add a define of your own for the unknown data type. There is no requirement to use a compiler that follows a newer version of the C standard. Or search and replace the data type with another the compiler knows. You have choices.
  • Lundin
    Lundin over 11 years
    @dwelch Of course you can define the type yourself, I haven't said anything to contradict that. But to find the header stdint.h you must use a newer compiler, as written in my post.