Re: Interesting preprocessor code behavior
Re: Interesting preprocessor code behavior
- Subject: Re: Interesting preprocessor code behavior
- From: "Clark Cox" <email@hidden>
- Date: Thu, 3 Jul 2008 13:40:22 -0700
On Thu, Jul 3, 2008 at 10:54 AM, Greg Guerin <email@hidden> wrote:
> Clark Cox wrote:
>
>> #if MY_UNDEFINED_SYMBOL == ONE
>> ...etc...
>
> The OP mentioned the problem was with #elif, which could be significant.
Regardless of whether #if or #elif is used, it is a compiler bug.
> The OP did not mention which version of gcc was used, which could also be
> significant.
Indeed, but that doesn't change the fact that this should work unconditionally.
>
> It was also not mentioned what the order of operands for the fail-case was.
> DEF==UNDEF could differ from UNDEF==DEF (and would be a bug).
>
> FWIW, the classical way to avoid the problem is:
> #if (defined(X) && ...expression involving X...)
Only if you want an undefined 'X' to mean something distinct from an
'X' defined to be zero. The standard guarantees that an undefined
identifier in an #if or #elif is identical in every way to a literal
zero (except when being tested with defined()). Any compiler that
doesn't live up to that guarantee is broken, and should have a bug
filed against it.
--
Clark S. Cox III
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden