By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,396 Members | 2,501 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,396 IT Pros & Developers. It's quick & easy.

Test if function defined?

P: 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/
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

Jul 19 '05 #2

P: n/a
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
Jul 19 '05 #3

P: n/a

"lallous" <la*****@lgwm.org> wrote in message
news:bl************@ID-161723.news.uni-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
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.