How to print a pound / hash via C preprocessor?

前端 未结 5 1668
失恋的感觉
失恋的感觉 2021-01-12 00:20

I need help doing the following:

a preprocessor macro label(x) shall output \"#x\", e.g.,

#define label(x) ...

if I call label(anam

5条回答
  •  攒了一身酷
    2021-01-12 01:05

    The answer is:

    #define hash #
    #define f(x) x
    #define label(a) f(hash)a
    

    then

    label(foobar)
    

    creates

    #foobar
    

    I found it with the help of all of you, but especially wintermute. Thanks a lot!

    (Using gcc 4.3.3)

提交回复
热议问题