Test if function defined?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lallous

    Test if function defined?

    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



  • Gianni Mariani

    #2
    Re: Test if function defined?

    lallous wrote:[color=blue]
    > 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?[/color]

    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.

    Comment

    • Attila Feher

      #3
      Re: Test if function defined?

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

      No, you cannot. You can test for a MACRO being defined or not.
      [color=blue]
      > 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?[/color]

      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


      Comment

      • Ashish

        #4
        Re: Test if function defined?


        "lallous" <lallous@lgwm.o rg> wrote in message
        news:blroul$fne 23$1@ID-161723.news.uni-berlin.de...[color=blue]
        > 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/
        >
        >[/color]

        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


        Comment

        Working...