开发者

## macro argument concatenation not working as I expected

开发者 https://www.devze.com 2023-02-27 05:12 出处:网络
Shouldn\'t this: #define MOGSH_CONCAT (x,开发者_开发百科y) x##y #define MOGSH_DOUBLE (a,b) MOGSH_CONCAT(a,b)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消