Test if function defined?

Discussion in 'C++' started by lallous, Oct 6, 2003.

  1. lallous

    lallous Guest

    Usually you can check for a defined variable as:
    #ifdef DEF1
    // do stuff here
    #endif

    Can I test if a function is defined then do things, example:
    int myFnc()
    {
    // blah blah
    }

    Later I do this:
    #ifndef myFnc
    #error myFnc does not exist!
    #endif

    Is there is a way to do that?

    --
    Elias
    http://lgwm.org/
     
    lallous, Oct 6, 2003
    #1
    1. Advertising

  2. lallous

    Attila Feher Guest

    lallous wrote:
    > Usually you can check for a defined variable as:
    > #ifdef DEF1
    > // do stuff here
    > #endif


    No, you cannot. You can test for a MACRO being defined or not.

    > Can I test if a function is defined then do things, example:
    > int myFnc()
    > {
    > // blah blah
    > }
    >
    > Later I do this:
    > #ifndef myFnc
    > #error myFnc does not exist!
    > #endif
    >
    > Is there is a way to do that?


    Nope. There might be some deep wizardry involving overload resolution
    tricks but I even doubt that. Usually what is done is to create come sort
    of "config" header which tells what is present and what is not.

    --
    Attila aka WW
     
    Attila Feher, Oct 6, 2003
    #2
    1. Advertising

  3. lallous wrote:
    > Usually you can check for a defined variable as:
    > #ifdef DEF1
    > // do stuff here
    > #endif
    >
    > Can I test if a function is defined then do things, example:
    > int myFnc()
    > {
    > // blah blah
    > }
    >
    > Later I do this:
    > #ifndef myFnc
    > #error myFnc does not exist!
    > #endif
    >
    > Is there is a way to do that?


    Not really. The preprocessor directives (#if*) are interpreted *before*
    the code in compiled so there is no connection between compiler
    idenifiers and pre-processor identifiers. One technique used is to
    "compile" the code and detect the error (missing identifier) and then
    create the "config.h" to use as part of a configuration step.
     
    Gianni Mariani, Oct 6, 2003
    #3
  4. lallous

    Ashish Guest

    "lallous" <> wrote in message
    news:blroul$fne23$-berlin.de...
    > Usually you can check for a defined variable as:
    > #ifdef DEF1
    > // do stuff here
    > #endif
    >
    > Can I test if a function is defined then do things, example:
    > int myFnc()
    > {
    > // blah blah
    > }
    >
    > Later I do this:
    > #ifndef myFnc
    > #error myFnc does not exist!
    > #endif
    >
    > Is there is a way to do that?
    >
    > --
    > Elias
    > http://lgwm.org/
    >
    >


    Your code wont link if the function is not defined. The compiler takes care
    of the error part, so that you dont have to.

    -Ashish
     
    Ashish, Oct 6, 2003
    #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. Oodini
    Replies:
    1
    Views:
    1,838
    Keith Thompson
    Sep 27, 2005
  2. Angel Tsankov
    Replies:
    1
    Views:
    896
    Victor Bazarov
    Apr 5, 2006
  3. Replies:
    1
    Views:
    539
    Sion Arrowsmith
    Jul 10, 2008
  4. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    762
    Skybuck Flying
    Oct 4, 2009
  5. Alok
    Replies:
    3
    Views:
    286
Loading...

Share This Page