We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi Here is the code I have problems with I an just starting to use this C compiler Have used many others, mainly closer to C99
#define Num_LANGUAGEs 6 enum _LANGUAGE { eUSING_LAN_START = -1, // This is always the First item eUSING_ENGLISH, eUSING_ITALIAN, eUSING_FRENCH_Can, eUSING_LAST_LANG // This is always the Last item }; #if Num_LANGUAGEs != eUSING_LAST_LANG #error "Warning Not enough Lang defined" #endif
The preprocessor runs before the C Compiler (this is the way all C compilers work). The preprocessor processes preprocessor directives (those statements that begin with a #). The preprocessor creates an output file (This is the *.I file that may be created). The preprocessor output file is the actual file that is compiled. The program you provided:
#if Num_LANGUAGEs != eUSING_LAST_LANG
Jon said, "The preprocessor runs before the C Compiler ... The preprocessor output file is the actual file that is compiled." That's the way I've always understood it Mike said, "in ANSI C the preprocessor doesn't know about enum definitions. I think it's allowed in C99" (my emphasis). If that is true, then surely that is a fundamental change to the very concept of the preprocessor - as outlined by Jon. Can anyone give chapter & verse on this?
If that is true, then surely that is a fundamental change to the very concept of the preprocessor Actually that is not true. I've made a mistake. Here is an extract from the C99 standard: The expression that controls conditional inclusion shall be an integer constant expression except that: it shall not contain a cast; identifiers (including those lexically identical to keywords) are interpreted as described below; (footnote 140) and it may contain unary operator expressions of the form defined identifier or defined ( identifier ) ... footnote 140: Because the controlling constant expression is evaluated during translation phase 4, all identifiers either are or are not macro names — there simply are no keywords, enumeration constants, etc. - mike
That's a relief!