【发布时间】:2012-10-24 15:33:08
【问题描述】:
可能重复:
Why don’t I get a segmentation fault when I write beyond the end of an array?
此代码编译并运行,没有任何错误。但是怎么做呢?
#include <stdio.h>
int main (void)
{
int foo[2];
foo[8] = 4; /* How could this happen? */
printf("%d\n", foo[8]);
return 0;
}
我正在 Arch Linux x86_64 上使用 GCC 4.7.2 进行编译。
gcc -Wall -o "main" "main.c"
【问题讨论】:
-
你很幸运应用没有崩溃。
-
@alk:不,崩溃是最好的结果。真的。
-
是的,你是对的。我不知何故使用了错误的措辞。 @EdS。
-
"为什么我没有收到分段错误?"很少(如果有的话)是一个有效的问题。