avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Bob Paddock
Subject: [avr-gcc-list] Can enumerator values be used in a #if preprocessor directive?
Date: Mon, 29 Aug 2011 14:37:26 -0400

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 'avr-gcc test.c' I get an a.out file and no errors.
If I include test.c in my project I get 'error: "last" is not defined'.
Why would it be defined in the standalone one and not defined in the other?

Looking in "C: A Reference Manual" 5th edition by Harbison and Steele they
make the distinction between "preprocessor constant expressions" and
"integral constant expressions" in section 7.11/7.11.1.  In 7.11.1
enums are not listed as a allowable type to #if.  If that is the case
why does the standalone compile of test.c compile?  If that is not the
case why is 'last' not defined?

I'm confused by this inconstancy, what am I overlooking here?

The goal in my real code is to know when I've assigned more than 254
enums in one enumerator set.
Is there a different way to do this?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]