Does "#if 1 func1 #else func2 #endif execute func1 during executation?

Discussion in 'C++' started by Mr. Ken, Sep 6, 2006.

  1. Mr. Ken

    Mr. Ken Guest

    In the file I received, it defines two versions of same function with such
    statement.
    Is it during compilation, func1 will be used?

    #if 1
    func1.....
    #else
    func1.....
    #endif

    Sorry for the silly question but I am a little confused now.
    Mr. Ken, Sep 6, 2006
    #1
    1. Advertising

  2. Mr. Ken

    Bart Guest

    Mr. Ken wrote:
    > In the file I received, it defines two versions of same function with such
    > statement.
    > Is it during compilation, func1 will be used?
    >
    > #if 1
    > func1.....
    > #else
    > func1.....
    > #endif
    >
    > Sorry for the silly question but I am a little confused now.


    Here the first version (#if 1) will be compiled and the second version
    (#else) will be ignored. The function will not be used at compile time.
    This is just a way to compile a different version of the function.

    Regards,
    Bart.
    Bart, Sep 6, 2006
    #2
    1. Advertising

  3. Mr. Ken

    Mr. Ken Guest

    "Bart" <> wrote in message
    news:...
    > Mr. Ken wrote:
    > > In the file I received, it defines two versions of same function with

    such
    > > statement.
    > > Is it during compilation, func1 will be used?
    > >
    > > #if 1
    > > func1.....
    > > #else
    > > func1.....
    > > #endif
    > >
    > > Sorry for the silly question but I am a little confused now.

    >
    > Here the first version (#if 1) will be compiled and the second version
    > (#else) will be ignored. The function will not be used at compile time.
    > This is just a way to compile a different version of the function.
    >
    > Regards,
    > Bart.
    >


    Thank you Bart.
    Mr. Ken, Sep 6, 2006
    #3
  4. Mr. Ken

    Guest

    Mr. Ken wrote:
    > "Bart" <> wrote in message
    > news:...
    > > Mr. Ken wrote:
    > > > In the file I received, it defines two versions of same function with

    > such
    > > > statement.
    > > > Is it during compilation, func1 will be used?
    > > >
    > > > #if 1
    > > > func1.....
    > > > #else
    > > > func1.....
    > > > #endif
    > > >
    > > > Sorry for the silly question but I am a little confused now.

    > >
    > > Here the first version (#if 1) will be compiled and the second version
    > > (#else) will be ignored. The function will not be used at compile time.
    > > This is just a way to compile a different version of the function.
    > >
    > > Regards,
    > > Bart.
    > >

    >
    > Thank you Bart.


    Code under #if 1 always compiles and gets embedded in to object file.
    You may find #if 0 in some code where in the code under it will not
    compile.

    - Bharath
    , Sep 7, 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. Christopher M. Lusardi
    Replies:
    1
    Views:
    415
    Victor Bazarov
    Nov 19, 2004
  2. Replies:
    3
    Views:
    429
    Howard
    May 18, 2005
  3. Christopher M. Lusardi
    Replies:
    1
    Views:
    331
    Victor Bazarov
    Nov 19, 2004
  4. Steve Ferg
    Replies:
    45
    Views:
    1,806
    James Harris
    Dec 4, 2009
  5. Replies:
    2
    Views:
    242
Loading...

Share This Page