Connecting Tech Pros Worldwide Help | Site Map

Test if function defined?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 06:55 PM
lallous
Guest
 
Posts: n/a
Default 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
http://lgwm.org/



  #2  
Old July 19th, 2005, 06:55 PM
Gianni Mariani
Guest
 
Posts: n/a
Default 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, 06:55 PM
Attila Feher
Guest
 
Posts: n/a
Default 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, 06:56 PM
Ashish
Guest
 
Posts: n/a
Default 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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.