Why can't I cause a seg fault?

前端 未结 10 1752
名媛妹妹
名媛妹妹 2020-12-31 00:24

OK for whatever reason I\'m having trouble causing a seg fault. I want to produce one so that I can use gdb to see how to debug one. I have tried both examples

10条回答
  •  渐次进展
    2020-12-31 01:16

    Both of the things you do will produce "undefined behaviour" in C++ (well, calling main() is actually explicitly forbidden). There is no guarantee that they will cause seg faults - this will depend on a lot of things, but mostly the platform you are running on, which you haven't specified.

    In fact, any suggested method of causing a seg fault may or may not work. This is because a seg fault is almost always associated with C++'s concept of undefined behaviour.

提交回复
热议问题