[avr-gcc-list] Can enumerator values be used in a #if preprocessor directive?

2011-08-29 Thread Bob Paddock
I have the following file test.c: #define MAX (2U) enum ENUM_EXAMPLE{ a, b, c, d, e, last }; #if( last = MAX ) #error Last is greater than MAX. #endif /* * Never get as far as this main when compiling with other code to mater, * need for the standalone test: */ int main( void ) { } If I do

Re: [avr-gcc-list] Can enumerator values be used in a #if preprocessordirective?

2011-08-29 Thread Weddington, Eric
Hi Bob, The preprocessor runs, of course, before the compiler. So you're trying to check if an enum is greater than some value, when the compiler phase hasn't even evaluated the enum list and assigned values to last. For the preprocessor purposes, I would bet that somehow last evaluates to 0,

Re: [avr-gcc-list] Can enumerator values be used in a #if preprocessordirective?

2011-08-29 Thread Wim Lewis
On Mon, 29 Aug 2011, Weddington, Eric wrote: For the preprocessor purposes, I would bet that somehow last evaluates to 0, so of course the condition will always be true. Yes, I think this is part of the language standard (for better or worse). I don't have a standard cite but it's described

Re: [avr-gcc-list] Can enumerator values be used in a #if preprocessordirective?

2011-08-29 Thread Bob Paddock
On Mon, Aug 29, 2011 at 3:15 PM, Wim Lewis w...@.org wrote: On Mon, 29 Aug 2011, Weddington, Eric wrote: For the preprocessor purposes, I would bet that somehow last evaluates to 0, so of course the condition will always be true.   [6] Identifiers that are not macros, which are all

Re: [avr-gcc-list] Can enumerator values be used in a #if preprocessordirective?

2011-08-29 Thread Dave Hansen
From: graceindustr...@gmail.com [...] So that explains the difference. Seems like there could be a better error message for this case, 'don't use enum here', alas The preprocessor does not know anything about types in the language... Here's a cute/ugly little macro that might help you