It seems a bug crept in CC ARM, may be not only ARM. Consider next code:
#ifdef IDENTIFIER IDENTIFIER(); #endif
and build output:
..\..\src\module\module.cpp(344): error: #20: identifier "IDENTIFIER" is undefined
GCC does not have such problem. Check <a href=coliru.stacked-crooked.com/.../7e6350bd2bfbc14a >here</a>
In addition
//#define LED PA7 #ifdef LED led_on(LED); //if 1st string commented, we will get an error "undefined identifier" #endif
I have found workaround
#define LED 0 //PA7 #if LED led_on(LED); #endif
But I would like to have ability to undefine LED at all.
No - if LED isn't defined then you will not get any "undefined identifier" from the compiler, because you will not get inside the #ifdef/#endif block - the preprocessor will clear away the contents of that block. So you'll end up with three very empty lines:
And with LED defined to PA7, you end up with (assuming PA7 isn't also a #define)
led_on(PA7); <<<=== the preprocessor expansion of the LED define.
You are right about how preprocessor/compiler MUST do. And GCC gives such output, but not ARM. Have you tested? May be it is only my problem? Note this problem in .cpp file.
Have you ordered the compiler to just preprocess the data and looked at the output?
Post the output from the preprocessor. If the output is wrong, then it's time to contact Keil support.
By the way - you haven't posted specific version information for your tool set.
Lots of people are using the Keil tools.
And lots of people are using conditional compilation.
My code would fail badly if the preprocessor didn't do what it should - it doesn't with the versions I'm currently using. But I seldom jump onto the latest versions until I'm starting a new product. Existing products normally lives their whole life using the compiler that was used when the product was on beta testing. All to make sure that I can rebuild and get a binary-identical copy.
View all questions in Keil forum