如何打印通过C preprocessor磅/哈希? [英] How to print a pound / hash via C preprocessor?
问题描述
我需要帮助做以下几点:
I need help doing the following:
一个preprocessor宏标签(X)须输出#X,如,
a preprocessor macro label(x) shall output "#x", e.g.,
#define label(x) ...
如果我叫标签(aname),输出应为#aname(W / O引号)
if I call label(aname), the output shall be "#aname" (w/o quotes)
我知道,那下面的尝试是错误的。
I know, that the following tries were errors.
#define label(x) #x // leads to "x"
#define label(x) \#x // is \"x"
#define label(x) "#x" // is "#x" (but not the content of x") "#otto"
这可能存在一种转义#(磅),但我不知道,如何逃生...
It may exist a kind of escaped # (pound), but I don't know, how to escape...
修改:我跑-E的gcc -o测试的test.html获取输出。问题的关键是:我如何与万客隆打印出井号(#)只使用preprocessor的能力。
Edit: I run "gcc -E test -o test.html" to get the output. The point is: How do I print out a hash mark (#) with a makro only using preprocessor's capabilities?
推荐答案
答案是:
#define hash #
#define f(x) x
#define label(a) f(hash)a
然后
label(foobar)
创建
#foobar
我发现它的帮助下的你们,尤其是wintermute。
非常感谢!
I found it with the help of all of you, but especially wintermute. Thanks a lot!
(使用GCC 4.3.3)
(Using gcc 4.3.3)
这篇关于如何打印通过C preprocessor磅/哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!