7

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?

timrau
  • 22,578
  • 4
  • 51
  • 64
dccharacter
  • 421
  • 1
  • 4
  • 14
  • 4
    How do you know the include you added defined uint8_t ? Maybe try to add 'typedef unsigned char uint8_t;' before that definition... either it will help or it will complain you are redefining it. – Matthieu Jan 07 '13 at 14:38
  • You probably need `#include ` for `uint8_t`. – Paul R Jan 07 '13 at 14:41
  • `xbee_api.h:19:` can you also give line numbers of your code? at least the number of first line? So that we can know, which line is giving problem. – anishsane Jan 07 '13 at 14:43
  • If `_pack_struct` is an abbreviation of "packet structure", I would advise against it lest it is confused with "packed structure" which is a different thing. – Clifford Jan 07 '13 at 14:53

1 Answers1

9

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

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • I thought it was a super-stupid mistake. That was it. Thank you. – dccharacter Jan 07 '13 at 14:52
  • 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. – old_timer Jan 08 '13 at 04:23
  • @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. – Lundin Jan 08 '13 at 07:18