Could I implement this in C?
#define X abc
then X_menu();
will be preprocessed as abc_menu();
In another build
if I define X def
then X_menu();
will be def_menu();
I'm sure there should be a method, but I could not figure out.
Could I implement this in C?
#define X abc
then X_menu();
will be preprocessed as abc_menu();
In another build
if I define X def
then X_menu();
will be def_menu();
I'm sure there should be a method, but I could not figure out.
No, you wouldn't want this behavior as it would be very unsafe and difficult to deal with replacing every X
in every name. However, you could use a macro function to do something similar
#define X(F) abc##F
X(_menu();)
##
is macro concatenation, so X(_menu();)
will expand to abc_menu();
As Roger points out, the macro will also work with the syntax
X(_menu)();
which you may find easier to read