Reputation: 1082
I have a not very well documented c library which allows me to override some functions. But sadly there are no examples :(
library.h:
#ifndef some_function
uint8_t some_function(void);
#endif
So I defined a function like this in my c++ code:
#include "library.h"
extern "C" uint8_t some_function(void) { return 0;}
void main() {
....
}
but it uses the code define in the library.
Next try:
#define some_function
#include "library.h"
uint8_t some_function(void) { return 0;}
results in:
src/main.cpp: error: expected unqualified-id before 'void'
extern "C" uint8_t some_function(void);
because function name is replaced by the define.
Any suggestions?
Upvotes: 2
Views: 365
Reputation: 19133
Any suggestions?
#define some_function some_function
Not advocating for this, of course, but it should work.
Maybe the author wanted to allow the users to define their own functions with different names. I.e. the macro is not meant as much for you, as for the library to use a custom function name.
uint8_t my_function(void) { return 0;}
...
#define some_function my_function
#include "library.h"
If no one defined such macro, the author defined a function with the same so all the calls would work.
Upvotes: 3