好,我咬。一个answer到广受欢迎的Why does the C preprocessor interpret the word "linux" as the constant "1"?问题提到
main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}`
prints "unix"
, but for reasons that have absolutely nothing to do with the spelling of the macro name.
我读了http://www.ioccc.org/1987/korn.hint但我认为更多的细节将有助于消除混淆:)
unix
为 1,因为编译器或运行时环境中的隐式 #define
。
因此,因为 a[b] == b[a] == *(a + b)
因此 1["xy"] == "xy"[1 ]
,你得到:
&unix["\021%six\012\0"]
指向 "%six\012\0"
(unix)["have"] = "have"[1] = 'a'
,
"'a'+"fun"-0x60"= "fun"+ 1 = "un"
。
这会将您带到 printf("%six\012\0", "un");
显然会打印 "unix\012"
, \012
是换行符(与 \n
相同)。
如果 unix
未定义,e. G。在 Windows 系统上,您会收到错误消息。
如果 unix
是 0
(在干净的系统上会是这样吗?),你会得到
printf("\012%six\n", 'h'+"fun"-0x60)
第二个参数是 "fun"+8
,指向 Nirvana 并导致未定义的行为。