Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C: typedef union

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?

like image 778
dccharacter Avatar asked Jan 07 '13 14:01

dccharacter


1 Answers

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

like image 150
Lundin Avatar answered Sep 30 '22 02:09

Lundin