danmc77 0 Report post Posted September 17, 2008 Guys, Take a look at this very simple program: --------------------------------------------------------------------- #include <system.h> #include <icd2.h> #include <string.h> #include <float.h> enum Bypass_PosN {BYP_OFF,BYP_OPEN,BYP_CLOSE}; void main() { Bypass_PosN=BYP_OFF; } --------------------------------------------------------------------- When I try to build this, I get this: C:\debug\test.c(9): error: general error C:\debug\test.c(9): error: failure Now, if I change Bypass_PosN in the enum declaration to something else like, Bypass_Pos, then I get this: C:\debug\test.c(10:2): error: unknown identifier 'Bypass_PosN' C:\debug\test.c(10:2): error: invalid operand 'Bypass_PosN' C:\debug\test.c(10:13): error: failed to generate expression Something is not right here. I'm using PIC18 rev 6.89. Please take a look. Thanks, Dan Quote Share this post Link to post Share on other sites
Pavel 0 Report post Posted September 18, 2008 Compiler behaviour is correct. This is not valid C code :angry: Regards, Pavel Quote Share this post Link to post Share on other sites
Reynard 0 Report post Posted September 18, 2008 Dan, An enum name is not a variable but a data type. Whether it is a unsigned char or int will depend on the size of the enum values. i.e. if you have BYP_CLOSE=1000, then the compiler will make the variable (fred) a unsigned int. The compiler will use the smallest data type it can. #include <system.h> enum Bypass_Position {BYP_OFF,BYP_OPEN,BYP_CLOSE}; enum Bypass_Position fred; void main() { fred = BYP_OPEN; } Cheers Reynard Quote Share this post Link to post Share on other sites
danmc77 0 Report post Posted September 18, 2008 Dan, An enum name is not a variable but a data type. Whether it is a unsigned char or int will depend on the size of the enum values. i.e. if you have BYP_CLOSE=1000, then the compiler will make the variable (fred) a unsigned int. The compiler will use the smallest data type it can. #include <system.h> enum Bypass_Position {BYP_OFF,BYP_OPEN,BYP_CLOSE}; enum Bypass_Position fred; void main() { fred = BYP_OPEN; } Cheers Reynard Pavel, Reynard, Thank you so much for correcting my foolishness. Humbly, Dan Quote Share this post Link to post Share on other sites