hexreader wrote: ↑10 Oct 2020 01:12
The #ifdef and #ifndef directives can be used anywhere #if can be used and they can test whether an identifier is currently defined or not. The line
#ifdef identifier
has exactly the same effect as #if 1 if identifier is currently defined, and the same effect as #if 0 if identifier is currently undefined. The other directive, #ifndef, tests true for the “not-defined” condition, producing the opposite results.
The syntax thereafter follows that of #if, #elif, #else, and #endif.
An identifier defined as NULL is considered to be defined.
I think this answers the question
Yeah, I saw that [and read it
]. The reason why I don't think it answers the question is it doesn't treat the case where
#if is used on an identifier that was not EVER defined. I want to know if the compiler writer(s) took this case into consideration, and handled it. I need to know if I can expect well-defined behavior, or will code like this fall into the Twilight Zone of undefined behavior.
Yes,
#ifdef does this, and yes
#ifdef has the same effect as
#if 0, if the identifier is currently undefined, BUT that says NOTHING about what happens if I use
#if on an identifier that is currently
not defined. Is it treated like
#if 0? THAT's the thing I want to verify. And I need definitive verification, because this code is going into a product.
Otherwise, I'm going to have to do every dang code selection like this:
Code: Select all
void main()
{
#ifdef NOT_DEFINED
#if NOT_DEFINED
// Some elective code
#endif
#endif
}
And, yeah, I know a better solution would probably be to use header files to select code for different hardware options, but the Mikroe IDE doesn't seem to be able to follow logic into included header files! Like, for instance if I want to use the IDE to navigate to a function defined in one of the header files.