function.c (I can't edit this file)
#define FOO 1
#if FOO == 1
void Foo() {}
#endif
cpp
class MyClass
{
#if FOO == 1
void CppFoo()
{
Foo();
}
#endif
}
I want to do the same thing, but without using the define TEST in the main.cpp file
What I want to do:
class MyClass
{
#if (extern "c" Foo() exist)
void CppFoo()
{
Foo();
}
#endif
}
The CppFoo() method will not have to be declared if the static function Foo() has not been declared.
How can I do this?
You can use a weak attribute, for example:
file a.c:
File b.c:
Now if you do not compile and link b.c, then the default (no-op) function
foo()is called, otherwise the functionfoo()from b.c.