conditional compilation

Discussion in 'C++' started by Gary Wessle, Oct 26, 2006.

  1. Gary Wessle

    Gary Wessle Guest

    Hi

    I need to create an object of her_t OR his_t inside a namespace. the
    choice should be decided based on a macro. did the following
    accomplish this?

    thank you.

    // macro
    // uncomment ONLY ONE of the 2 lines below
    #define HIS
    //#define HER


    namespace s_inf
    {
    ....

    #ifdef HIS
    his_t conn; // FXGame OR FXTrade
    #endif

    #ifdef HER
    her_t conn;
    #endif

    ....
    }

    the above created his_t and NOT her_t object. right?

    // place in a ".h" file and #include it in ".cpp" file and use the
    object "conn".
    Gary Wessle, Oct 26, 2006
    #1
    1. Advertising

  2. Gary Wessle

    Leo Guest

    Yeah, It will.
    When you start compiling, your code is done.
    Gary Wessle wrote:
    > Hi
    >
    > I need to create an object of her_t OR his_t inside a namespace. the
    > choice should be decided based on a macro. did the following
    > accomplish this?
    >
    > thank you.
    >
    > // macro
    > // uncomment ONLY ONE of the 2 lines below
    > #define HIS
    > //#define HER
    >
    >
    > namespace s_inf
    > {
    > ...
    >
    > #ifdef HIS
    > his_t conn; // FXGame OR FXTrade
    > #endif
    >
    > #ifdef HER
    > her_t conn;
    > #endif
    >
    > ...
    > }
    >
    > the above created his_t and NOT her_t object. right?
    >
    > // place in a ".h" file and #include it in ".cpp" file and use the
    > object "conn".
    Leo, Oct 26, 2006
    #2
    1. Advertising

  3. Gary Wessle posted:

    > I need to create an object of her_t OR his_t inside a namespace. the
    > choice should be decided based on a macro.



    #ifdef MALE
    typedef his_t Type;
    #else
    #ifdef FEMALE
    typedef her_t Type;
    #else
    #error "You must #define either MALE or FEMALE."
    #endif
    #endif

    namespace MyNa {

    Type obj;
    }

    --

    Frederick Gotham
    Frederick Gotham, Oct 26, 2006
    #3
  4. Gary Wessle

    red floyd Guest

    Frederick Gotham wrote:
    > Gary Wessle posted:
    >
    >> I need to create an object of her_t OR his_t inside a namespace. the
    >> choice should be decided based on a macro.

    >
    >
    > #ifdef MALE
    > typedef his_t Type;
    > #else
    > #ifdef FEMALE
    > typedef her_t Type;
    > #else
    > #error "You must #define either MALE or FEMALE."
    > #endif
    > #endif
    >
    > namespace MyNa {
    >
    > Type obj;
    > }
    >


    #if defined(MALE)
    typedef his_t Type;
    #elif defined(FEMALE)
    typedef her_t Type;
    #else
    #error "You must #define either MALE or FEMALE
    #endif
    red floyd, Oct 26, 2006
    #4
    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. Chris P
    Replies:
    0
    Views:
    431
    Chris P
    Oct 28, 2003
  2. avishay

    Conditional compilation in VHDL

    avishay, Aug 1, 2005, in forum: VHDL
    Replies:
    4
    Views:
    2,989
    Andy Peters
    Aug 1, 2005
  3. Praveen
    Replies:
    0
    Views:
    347
    Praveen
    Apr 12, 2005
  4. Praveen Ramesh
    Replies:
    2
    Views:
    2,149
    Steven Cheng[MSFT]
    Apr 13, 2005
  5. Alec S.
    Replies:
    10
    Views:
    10,091
    Alec S.
    Apr 16, 2005
Loading...

Share This Page