C: typedef union

独自空忆成欢 提交于 2020-01-03 10:42:48

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/14197998/c-typedef-union

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!