Hi,
I got the source code of a library. Its header file has following lines:
Code:
typedef int coord;
#define SIZE 8;
#define MYPOW(v) fabs(v)
I like to modify these definitions in a new function added to the header and recompile the library, so that I can call this function from my program to make "coord", "SIZE" and "MYPOW" defined in another way depending on some condition, something like
Code:
void definition(int i){
if (i > 0) {
typedef int coord;
#define SIZE 8
#define MYPOW(v) ((v)*(v)) }
else {
typedef double coord;
#define SIZE 16
#define MYPOW(v) fabs(v) }
}
I know this is not correct. Does C/C++ have something like conditional definition not using directives? Even if they do, how to make the symbols "coord", "SIZE" and "MYPOW" global, instead of being only effective within the function and not exiting outside?
For example, "coord" in the following code will not exist outside the function definition() and will not be available to use.
Code:
void definition(int i){
if (i>0) {typedef int coord ;}
else {typedef float coord ;}
}
For the function-like macro MYPOW, I can think of a way as
Code:
double (*MYPOW) (double);
double square(double v) {return ((v)*(v));}
void definition(int i){
if (i > 0) {MYPOW = &fabs;}
else {MYPOW = □}
}
Really appreciate your help!
Thanks and regards!