On 29/08/2011 22:03, Dave Hansen wrote:
> 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 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: enum{a,b,c,d,last}; #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,
Does that mean I am not allowed to post my refinements? Hint - you want to use typedefs to avoid making extra symbols, you want to make sure you can use it as many times as you want in the same file, and you want to be able to use it inside functions as well as outside. And if you are like me and like extra warnings to keep your source code neat, it has to work with -Wnested-externs and -Wredundant-decls as well.
_______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org https://lists.nongnu.org/mailman/listinfo/avr-gcc-list