Connecting Tech Pros Worldwide Forums | Help | Site Map

Test if function defined?

lallous
Guest
 
Posts: n/a
#1: Jul 19 '05
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/



Gianni Mariani
Guest
 
Posts: n/a
#2: Jul 19 '05

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.

Attila Feher
Guest
 
Posts: n/a
#3: Jul 19 '05

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


Ashish
Guest
 
Posts: n/a
#4: Jul 19 '05

re: Test if function defined?



"lallous" <lallous@lgwm.org> wrote in message
news:blroul$fne23$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


Closed Thread