【发布时间】:2012-03-18 05:11:57
【问题描述】:
我想出了一种方法,可以在阅读 C-FAQs 的同时同时让所有 printfs 静音。
你能告诉我这是如何工作的吗?程序:
#include<stdio.h>
//How to silence all printfs at once!!!
#define printf (void)
#define ab a b c d e f
#define xstr(a) str(a)
#define str(a) #a
#define string "The politicians do not even know the" xstr(ab) "of politics"
main(){
char *all=str(a b c d e f);
printf("%s\n",all);
printf(string);
}
程序的输出为空白。我的意思是它根本不打印任何东西。如果我#define printf 为:
/ #define printf
这也是同样的行为。我不明白 GCC 在这两种情况下是如何编译调用的。绝对没有错误和警告。
- 第一种情况
printf变为:(void)("%s\n",all); - 第二种情况
printf变成:("%s\n",all);
【问题讨论】:
-
第二个
printf变成(void)("The politicians do not even know the" "a b c d e f" "of politics"); -
是的,不知何故错过了。对不起。刚刚用 -E 选项编译并看到了:)