我有一个非常的简单程序,但它不起作用。此外,它让我严重怀疑程序的流程。
程序是这样的(假设有必要的标题):
main(){
printf("hello1");
printf("hello2");
somefunction();
}
输出至少是奇特的:它只返回第一个 printf(hello1),之后程序立即退出并出现错误“Segmentation fault 11”。 但是,如果我删除“somefunction()”,第二个 printf 也会显示。
我的意思是,如果我的“somefunction()”有问题,第二个 printf() 无论如何都应该显示。
最佳答案
您的 somefunction
做了一些令人讨厌的事情,并且在 printf
有机会刷新缓冲区之前进程被终止。你可以试试:
printf("hello1");
printf("hello2");
fflush(stdout);
somefunction();
关于c - gcc4.2.1 无法解释的错误 (Segm.fault 11),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9851999/