Test if function defined?

L

lallous

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?
 
A

Attila Feher

lallous said:
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.
 
G

Gianni Mariani

lallous said:
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.
 
A

Ashish

lallous said:
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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top