Difference between ifdef and if defined?

This is a discussion on Difference between ifdef and if defined? within the C++ Programming forums, part of the General Programming Boards category; What is the difference between using #ifdef and #if defined? I've seen comments in code like "Here we had to ...

  1. #1
    z33z
    Guest

    Difference between ifdef and if defined?

    What is the difference between using #ifdef and #if defined? I've seen comments in code like "Here we had to use the horrible ifdef", but no comments on if defined in the same code. So what's the difference?

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Some compilers won't read #if defined, but I am pretty sure all of them support #ifdef
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    i've never seen an 'if defined' directive... i'd presume that there is a condition 'defined', and it's tested as an if in an 'if'... seeing as how that's how it appears off hand... this is interesting, can someone explain? thanks...
    hasafraggin shizigishin oppashigger...

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    > What is the difference between using #ifdef and #if defined?

    #ifdef FOO
    and
    #if defined(FOO)
    are the same,

    but to do several things at once, you can use defined, like
    #if defined(FOO) || defined(BAR)
    /* some stuff */
    #endif

    With only #ifdef, it gets really messy
    #ifdef FOO
    /* some stuff */
    #endif
    #ifdef BAR
    #ifndef FOO /* in case FOO has already done it */
    /* some stuff */
    #endif
    #endif
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Difference between ifdef and if defined?
    If you're deaf than get a hearing aid, and if you can't find one than ignore what you don't understand, just keep going.

  6. #6
    z33z
    Guest
    Huh? Shouldn't you understand what you're doing? That doesn't sound like a good advice..

  7. #7
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    >If you're deaf than get a hearing aid, and if you can't find one than ignore what you don't understand, just keep going.

    niice... and wow that's pretty interesting... never would have figured... too bad i'm on hiatus tho... dang...
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21