## macro argument concatenation not working as I expected
Shouldn't this:
#define MOGSH_CONCAT (x,开发者_开发百科y) x##y
#define MOGSH_DOUBLE (a,b) MOGSH_CONCAT(a,b)
#define MOGSH_DEFINEPROC (p) MOGSH_DOUBLE(_gt,p) options_dialog::p;
MOGSH_DEFINEPROC(AssignMainForm);
happily expand to:
_gtAssignMainForm options_dialog::AssignMainForm;
Given that _gt
is not defined, _gtAssignMainForm
is:
typedef void (__stdcall *_gtAssignMainForm)();
and options_dialog
is just a class where AssignMainForm
is a static member.
Instead, in MSVC9, I get the error:
'a' : undeclared identifier
on the line containing
MOGSH_DEFINEPROC(AssignMainForm);
In the definition of a function-like macro there can be no whitespace between the macro name and the (
beginning the parameter list.
#define MOGSH_CONCAT(x,y) x##y
// ^ no whitespace allowed here
As you have it now (with whitespace), MOGSH_CONCAT
is an object-like macro with a replacement list of (x,y) x##y
, which is why you are getting such strange results.
精彩评论