c++ - Writing a Preprocessor Function: Is the syntax correct -
i experimenting preprocessor function-like macros trying write macro forwards declares regular functions. when go compile says line 2 has wrong syntax.
what doing wrong?
#define forward_declare_custom_funct(fname) "int" #fname "(int id, string msg, string cmd);" forward_declare_custom_funct("abc") // line 2: should become "int abc(int id, string msg, string cmd);" void test() { abc(1, "", ""); }
the problem of quotation marks.
#define forward_declare_custom_funct(fname) "int" #fname "(int id, string msg, string cmd);" translates (after concatenating string literals):
"int abc (int id, string msg, string cmd);" whereas,
#define forward_declare_custom_funct(fname) int #fname (int id, string msg, string cmd); translates to:
int "abc" (int id, string msg, string cmd); what need simply:
#define forward_declare_custom_funct(fname) int fname (int id, string msg, string cmd); use this:
forward_declare_custom_funct(abc) it's text replacement. remove semicolon in macro , create user set 1 in after each utilize well, create more statement. feels more natural me.
c++ c-preprocessor
No comments:
Post a Comment