2021-07-14 04:35 PM
I have a __BOOTLOADER symbol defined for my project as shown in the attached image
I want to display firmware version based on the defined symbol so I have an #ifdef statement to select the correct string. The IDE displays the source code correctly: the greyed/ungreyed sections are displayed as expected.
But when I run the program, GB_FW_REV[] = "5.26.1" instead of "5.26.B".
What am I doing wrong?
Thanks!
2021-07-14 06:39 PM
Is this in a C file or C++? Your #define is in C.
Make sure you're on the same build configuration as you have the #define set up in. Release or Debug.
Do a sanity check and put some invalid syntax in the part you think it should be running to see if the compiler is compiling what you think it is.
2021-07-15 04:57 AM
Thanks for responding!
This is in a C file.
It's as if, at the time this file is compiled, none of those symbols are known yet, so it defaults to the last line.
But I forgot to mention, I did do a sanity check by commenting all the other #elifs and just leaving
#ifdef __BOOTLOADER
const u08 GB_FW_REV[MAX_FW_LEN] = {"5.26.B"};
#endif
When i do that, GB_FW_REV[] = "5.26.B" as expected!
2021-07-15 06:19 AM
You can add a compiler flag to output all known defines. If the simpler version works, I'm guessing something else is going on.
You can also verify the define gets set correctly by looking at the command line compilation of that file.
2021-07-18 11:38 PM
@gsieb.1is #elseif leading to same ?
2021-07-19 04:34 AM
I am not absolutely sure, but i think, that #elif is possibe to use after #if, not after #ifdef.
2021-07-19 08:46 AM
Thanks everyone for responding!
@Cartu38 OpenDev : I did not know that "__" (2 underscores) plus an upper case char is something reserved by the compiler (I'm not clear on that rule), but to make sure it's not causing a problem, I replaced "__BOOTLOADER" to "BOOTLOADER" throughout the code with no effect.
Also, "#elseif" does not seem to be supported...?
@ONadr.1 : I tried changing the format from #ifdef <SYMBOL1> #elif <SYMBOL2>... to #if defined(<SYMBOL1>) #elif defined (<SYMBOL2>) ... with no effect
@TDK : I could not find a flag that will force the compiler or linker to generate a list of #define symbols. Do you happen to know how?
So with my current settings and code, (changes made based on all advice received) the result at runtime is still GB_FW_REV[] = "5.26.1" even though it should clearly not be.
If I remove the preprocessor symbol "BOOTLOADER" from the settings and instead add" #define BOOTLOADER" in my code, then the result is GB_FW_REV[] = "5.26.B" as expected.
2021-07-19 09:01 AM
Solved!
Stupid mistake: the build configuration that I had selected as the active build configuration was not the same build configuration that I was debugging.
@Cartu38 OpenDev , @TDK, @ONadr.1 , thanks again for responding.