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

  1. you defining structure within typedef , aliasing pinstruct -- no errors.
  2. you include first header file -- no errors.
  3. you use pinstruct in function declaration of foo -- 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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -