你能帮我一个简短code,可以打印自己? [英] Can you help me with a short code that can print itself?
问题描述
#define q(k)main(){return!puts(#k"\nq("#k")");}
q(#define q(k)main(){return!puts(#k"\nq("#k")");})
这code可以在屏幕上打印本身,但是,我有困难阅读它,尤其是两个#K,它是如何工作的?我知道问:如何#定义(K)2 * K的作品,但我真的没有这code.请主意帮我分析吧!谢谢!
This code can print itself on the screen,however,I have a difficulty in reading it,especially that two #K,how does it work?I know how #define q(k) 2*k works,but I really have no idea about this code.Please help me to analyse it!thank you!
推荐答案
简化呼叫,并用你的编译器的preprocessor,看看是怎么回事:
Simplify the call and use your compiler's preprocessor to see what is going on:
#define q(k)main(){puts(#k"hello("#k")");}
q(argument)
运行的gcc -E
上,让你:
main(){puts("argument""hello(""argument"")");}
正如你所看到的,什么情况是,该参数的①
宏被改造成一个字符串(因为被用作 #K
- 这有时被称为字符串化)。有没有其他的魔法会在这里。
As you can see, what happens is that the argument to the q
macro gets transformed into a string (because is is used as #k
- this is sometimes called "stringification"). There is no other magic going on here.
这篇关于你能帮我一个简短code,可以打印自己?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!