有没有办法放置这样的定义:
#define PUTVAL 0x00
#define foo(x) ("x")
int main()
{
char *szFoo = foo(PUTVAL);
return 0;
}
并通过宏对其进行修改,即szFoo将指向包含“ x”的“ 0x00” istead的stringliteral吗?
是的,您必须使用两个级别的宏,这称为stringification:
http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
#define xstr(s) str(s)
#define str(s) #s
#define foo 4
str (foo)
==> "foo"
xstr (foo)
==> xstr (4)
==> str (4)
==> "4"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句