In C I’m aware that an array index out of bounds will produce a segmentation fault. Is it the same for a stack overflow in C and there will also be a segmentation fault i.e. same error type for a similar problem?
C中无法保证会出现分段错误. C标准说它是undefined behaviour并且保留它.它可能表现出来,取决于实现/平台.
Or is it sometimes something much worse and a stack overflow in C could cause an operating system failure and force you to power cycle to get back? Or even worse, cause irreversible hardware damage? How bad effects can a stack overflow mistake have?
在现代操作系统中,很少有任何不幸发生在系统上;通常,只有程序会崩溃.现代操作系统使用various memory protection techniques.
It seems clear that the protection is better in Java than in C. Is it any better in C than in assembly / machine code or is it practically the same (lack of) protection in C as a assembly?
那是因为在Java中,内存是“被管理的”.在C中,它留给程序员;这是设计的. C编译器最终生成机器代码;所以它不会更好或更糟.明显,
一个好的编译器可以检测到其中的一些问题并警告你,这与C语言相比,与汇编相比具有优势.