Connecting Tech Pros Worldwide Help | Site Map

Test if function defined?

  #1  
Old July 19th, 2005, 07:55 PM
lallous
Guest
 
Posts: n/a
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/


  #2  
Old July 19th, 2005, 07:55 PM
Gianni Mariani
Guest
 
Posts: n/a

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.

  #3  
Old July 19th, 2005, 07:55 PM
Attila Feher
Guest
 
Posts: n/a

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


  #4  
Old July 19th, 2005, 07:56 PM
Ashish
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i call a function defined in html script tags from asp page? thisis answers 19 November 5th, 2006 12:35 PM
Test if pointer points to allocated memory Andrew answers 34 November 14th, 2005 02:11 AM