#ifdef - Can It Be Used With Logic Such as OR / AND?

This is a discussion on #ifdef - Can It Be Used With Logic Such as OR / AND? within the C Programming forums, part of the General Programming Boards category; Hello, As is often the case when using #ifdef, I'm using #ifdef to distiguish compiler directives for the various platforms ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    dedham, MA
    Posts
    10

    #ifdef - Can It Be Used With Logic Such as OR / AND?

    Hello,

    As is often the case when using #ifdef, I'm using #ifdef to distiguish compiler directives for the various platforms that I'm using or the various compilers of which I'm using to compile.

    In my case, the 3 platforms are as follows:

    GCC
    ALPHA
    CC

    In some cases in the code, I would like to precede the code with a statement such as the following:

    #ifdef GCC || ALPHA

    However, the GCC compiler doesn't seem to like this:

    " warning: extra tokens at end of #ifdef directive"

    Therefore, does anyone know how to create a #ifdef statement that allows such conditions like this?

    Otherwise, I would have to do the following:

    #ifdef GCC

    some code

    #else if ALPHA
    same code as GCC

    Thanks in advance,
    dedham_ma_man

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    Yes, but you need to write

    #if defined(GCC) || defined(ALPHA)
    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.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    dedham, MA
    Posts
    10
    OK, thank you

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    #else if ALPHA
    It's #elif if you ever need it.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Digital Logic
    By strokebow in forum Tech Board
    Replies: 3
    Last Post: 12-09-2006, 12:05 PM
  2. Logic
    By LordBronz in forum C++ Programming
    Replies: 6
    Last Post: 05-23-2006, 05:41 PM
  3. Actors, cues, event based logic.
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 04-27-2006, 10:58 PM
  4. Circular Logic
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-15-2001, 08:10 PM

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