Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22004

C - #include and multiple typedefs

$
0
0

I'm writing an embedded C program in eclipse with gcc and can't see how to get around a certain issue. I have a typedef in a header file which is protected by an include guard. Since I use this typedef in multiple headers, I need to include it in other headers, however when I try to compile, no matter what I do, one of the headers cannot see the typedef and complains of an unknown type name.

I believe this illustrates the problem:

header a.h:

#ifndef _a_h
#define _a_h

typedef enum {
  USBD_OK   = 0,
  USBD_BUSY,
  USBD_FAIL,
}USBD_Status;

#endif

header b.h:

#ifndef _b_h
#define _b_h

#include "a.h"

extern USBD_Status USB_getStatus(void);

#endif

header c.h:

#ifndef _c_h
#define _c_h

#include "a.h"

extern USBD_Status USBD_Sync(void);

#endif

This always seems to result in the error "unknown type name 'USBD_Status'" as whichever header is compiled second cannot see the typedef. Removing the include guard from a.h results in the complaint that USBD_Status is being redeclared.

edit: I have double checked all include paths, all includes, all file names and all include guards - there are no duplicates or typos.


Viewing all articles
Browse latest Browse all 22004

Trending Articles