[SOLVED] typedef struct in header file not working

Posted By: OCMvL

[SOLVED] typedef struct in header file not working - 12/26/15 21:23

Hey all, I found some strange behaviour that I don't understand.

The following code works in the main.c file. However it crashes when placed in a header file at line: "} CPlayer;". Can someone explain why? Am I missing something?

Code:
typedef struct CPlayerStruct {
	char* someString;
	int someInt;
	void someFunction(struct CPlayerStruct* p);
} CPlayer;



I tried various combinations, but all crash with a compiler error.

Code:
typedef struct CPlayer {
	char* someString;
	int someInt;
	void someFunction(struct CPlayer* p); // CRASH
} CPlayer;

struct CPlayerStruct {
	char* someString;
	int someInt;
	void someFunction(struct CPlayerStruct* p);
}
typedef struct CPlayerStruct CPlayer; // CRASH


Thanks
Posted By: alibaba

Re: typedef struct in header file not working - 12/26/15 22:01

Is acknex.h included before?
Posted By: OCMvL

Re: typedef struct in header file not working - 12/26/15 22:30

Yeah it was. Thanks for the answer!

Found the problem however, my stupidity wink
The include-guard defined CPLAYER, so that word was reserved already.
© 2024 lite-C Forums