c - typedef'd struct not found by header -
i'm sure foolish, i'm stumped:
i have typedef'd struct declared in 1 header:
firstheader.h
typedef struct pin { uint8_t a; uint8_t b; } pinstruct;
i want use typedef'd struct in function declaration in header:
secondheader.h
#include "firstheader.h" void foo (const pinstruct *mypin);
despite typedef'd struct being defined in first header, , including first header in second header, compiler complains "identifier pinstruct undefined". please smack me , tell me i'm missing.
edit: comments guys. compiler marking function declaration in second header source of error. exact error wrote: error[pe020]: identifier "pinstruct" undefined.
what's strange if copy struct definition secondheader.h
header file, compiler complians re-definition of struct. knows there.
your code should work fine (tested both gcc
, clang
).
- you defining structure within
typedef
, aliasingpinstruct
-- no errors. - you include first header file -- no errors.
- you use
pinstruct
in function declaration offoo
-- no errors.
the error in c source file, have included header file of "file 2" in c source file of "file 2"? example:
// file file_1.h typedef ...
... and:
// file file_2.h #include "file_1.h" // function declaration.
... , lastly (error here):
// file 2.c #include "file_2.h" // forgot?
Comments
Post a Comment