new to c #define

Discussion in 'C Programming' started by ampeloso@gmail.com, Sep 8, 2006.

  1. Guest

    Hello,
    I am modifying some code and there is a #define with no value. It looks
    like its used for testing.There are several #ifdef references.Is this
    ignored if there is no value assigned?
    Thanks
    Mike
    , Sep 8, 2006
    #1
    1. Advertising

  2. In article <>,
    <> wrote:
    >I am modifying some code and there is a #define with no value. It looks
    >like its used for testing.There are several #ifdef references.Is this
    >ignored if there is no value assigned?


    No, a #define with no value defines the value as 0 but marks it as
    defined.

    Be careful using the variable in preprocessor expressions:

    #define FOO
    #define BAR 1
    /* BAZ is not defined at all */

    then taking each of the below individually:


    #ifdef FOO /* this is true */

    #ifdef BAR /* this is true */

    #ifdef BAZ /* this is false */

    #if FOO /* this is false because FOO's value 0 is substituted */

    #if BAR /* this is true because BAR's value 1 is substituted */

    #if BAZ /* this is false because all symbols remaining after
    preprocessing have 0 substituted for them, so
    0 is put in in place of BAZ */

    #if defined(FOO) /* this is true */

    #if defined(BAR) /* this is true */

    #if defined(BAZ) /* this is false */

    #if !FOO /* this is true because FOO is 0 and !0 is true */

    #if !BAR /* this is false because BAR is 1 and !1 is false */

    #if !BAZ /* this is true because remaining symbols have 0
    substituted for them, making this !0 which is true */
    --
    Is there any thing whereof it may be said, See, this is new? It hath
    been already of old time, which was before us. -- Ecclesiastes
    Walter Roberson, Sep 8, 2006
    #2
    1. Advertising

  3. Eric Sosman Guest

    wrote On 09/08/06 12:28,:
    > Hello,
    > I am modifying some code and there is a #define with no value. It looks
    > like its used for testing.There are several #ifdef references.Is this
    > ignored if there is no value assigned?


    The macro is defined, but with an empty value. If
    you use the macro somewhere, it will be replaced by its
    expansion, which is empty -- in effect, the macro just
    disappears.

    However, even though the macro's value is empty, the
    macro is defined. Since #ifdef and #if defined ... and
    #ifndef test the defined/undefined status and not the
    value, they will all "see" the macro.

    --
    Eric Sosman, Sep 8, 2006
    #3
  4. CBFalconer Guest

    wrote:
    >
    > I am modifying some code and there is a #define with no value. It
    > looks like its used for testing.There are several #ifdef references.Is
    > this ignored if there is no value assigned?


    What kind of a file or record field is "testing.There", and
    "references.Is"?

    --
    "The smaller aperture of the lid has been designed to prevent
    hedgehogs from entering the McFlurry container in the
    unfortunate incidence that the lid is littered"
    -- McDonalds, as quoted in Time, 2006-09-11
    CBFalconer, Sep 8, 2006
    #4
  5. -cnrc.gc.ca (Walter Roberson) writes:
    > In article <>,
    > <> wrote:
    >>I am modifying some code and there is a #define with no value. It looks
    >>like its used for testing.There are several #ifdef references.Is this
    >>ignored if there is no value assigned?

    >
    > No, a #define with no value defines the value as 0 but marks it as
    > defined.


    No, it expands to an empty sequence of tokens.

    Given "#define FOO", the directive "#if FOO" is illegal.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Sep 8, 2006
    #5
  6. Eric Sosman Guest

    CBFalconer wrote On 09/08/06 16:06,:
    > wrote:
    >
    >>I am modifying some code and there is a #define with no value. It
    >>looks like its used for testing.There are several #ifdef references.Is
    >>this ignored if there is no value assigned?

    >
    >
    > What kind of a file or record field is "testing.There", and
    > "references.Is"?


    Pedant traps.

    --
    Eric Sosman, Sep 8, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    34
    Views:
    7,827
  2. theotyflos
    Replies:
    3
    Views:
    443
    Thomas Matthews
    Feb 19, 2004
  3. robin liu
    Replies:
    3
    Views:
    803
    Robin Liu
    Apr 21, 2006
  4. Brian Takita

    #define _ and #define __

    Brian Takita, Jan 23, 2006, in forum: Ruby
    Replies:
    0
    Views:
    436
    Brian Takita
    Jan 23, 2006
  5. Replies:
    2
    Views:
    400
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page