On 2/9/09 11:24 AM, Clark Cox said:

>> Apple's headers inconsistently use #if and #ifdef.
>
>Because #if and #ifdef will both give the proper result in this
>instance (i.e. the GCC compiler either defines __LP64__ to true, or it
>doesn't define it at all), they are interchangeable.
>
>> I recommend:
>>
>> #if defined (__LP64__) && __LP64__
>
>FYI, there is no functional difference between:
>
>#if defined (SOMEMACRO) && SOMEMACRO
>
>and
>
>#if SOMEMACRO
>
>That is, the preprocessor treats any undefined identifier in an '#if'
>or '#elif" as if it were defined to be zero.

I'm not a language lawyer, but I believe the latter is not guaranteed to
evaluate to 0 if the macro is not defined.  However, I imagine 99% of
compilers will evaluate it to 0.  gcc certainly does.  This is the
reason for the existance of -Wundef I believe.

>> which will also not warn with -Wundef.
>
>My original #ifdef won't trigger this warning either

True of course.

>therefore it is
>the best of all options (i.e. it's concise, doesn't trigger warnings,
>and provides the correct result).

True if __LP64__ is either defined to something or not defined at all.
This is currently the case, but I could not find docs guaranteeing
this.  If it's ever defined to 0 then you'd have a problem.  And seeing
how Apple itself sometimes uses #if and sometimes #ifdef I think caution
is advised.

This is rather academic of course... :)

--
____________________________________________________________
Sean McBride, B. Eng                 s...@rogue-research.com
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to