• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Interesting preprocessor code behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interesting preprocessor code behavior


  • Subject: Re: Interesting preprocessor code behavior
  • From: "Clark Cox" <email@hidden>
  • Date: Thu, 3 Jul 2008 10:24:54 -0700

On Thu, Jul 3, 2008 at 8:55 AM, Howard Moon <email@hidden> wrote:
> Hi all,
>
>        I'm not sure this really belongs in an Xcode list, or if it's more of
> a general gcc (or even C++) item.  But I thought you might like to hear
> about this, in case you weren't aware or hadn't seen such a thing before.
>
>        Preprocessor comparisons (like #if (A==B)) cannot be relied upon to
> consistently pass OR fail if either symbol is undefined.

If this is true, then this is a bug in GCC. If you have a reproducible
case, please file a bug.

>From the C++ standard (16.1 4):
---
After all replacements due to macro expansion and the _defined_ unary operator
have been performed, all remaining identifiers and keywords, except
for true and false, are
replaced with the pp-number 0, and then each preprocessing token is
converted into a token.
---

Therefore, all identifiers and keywords, that are not macros, are not
used with the 'defined' operator are replaced with zero. My experience
bears this out:

[ccox@clarkco:~]% cat test.cpp
#define ZERO 0
#define ONE 1

#if MY_UNDEFINED_SYMBOL == ONE
#error Shouldnt get here
#endif

#if MY_UNDEFINED_SYMBOL != ZERO
#error Shouldnt get here
#endif

#if MY_UNDEFINED_SYMBOL == ZERO
#warning Success
#endif

#if MY_UNDEFINED_SYMBOL != ONE
#warning Success
#endif

#if MY_UNDEFINED_SYMBOL
#error Shouldnt get here
#else
#warning Success
#endif

#if !MY_UNDEFINED_SYMBOL
#warning Success
#else
#error Shouldnt get here
#endif

int main() { return 0; }
[ccox@clarkco:~]% c++ test.cpp
test.cpp:13:2: warning: #warning Success
test.cpp:17:2: warning: #warning Success
test.cpp:23:2: warning: #warning Success
test.cpp:27:2: warning: #warning Success

--
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

References: 
 >Interesting preprocessor code behavior (From: Howard Moon <email@hidden>)

  • Prev by Date: IB: Inserting a parent item in a splitview pane?
  • Next by Date: Re: IB: Inserting a parent item in a splitview pane?
  • Previous by thread: Interesting preprocessor code behavior
  • Next by thread: Re: Interesting preprocessor code behavior
  • Index(es):
    • Date
    • Thread