[Top][All Lists]

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

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

From: Dave Hansen
Subject: Re: [avr-gcc-list] Can enumerator values be used in a #if preprocessordirective?
Date: Mon, 29 Aug 2011 16:03:18 -0400

> From: address@hidden
> 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 find the errors you're looking for:

#define ctassert(n,e) extern unsigned char n[(e)?0:-1]

Here's an example of how you might use it:

#define MAX 2
ctassert(big_enough,(last <= MAX));

Note that the macro does not need to be invoked from within a function.  If the test fails, the error message is almost pretty good, depending on what you choose for the array name (sztest.c:6: error: size of array `big_enough' is negative).

Refinements of the concept left as an exercise for the reader.  Regards,


reply via email to

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