Why can't I cause a seg fault?

前端 未结 10 1774
名媛妹妹
名媛妹妹 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:12

    It impossable to try and reliable do it dereferencing pointers.
    This is because how the application handles memory can vary from compiler to compiler also across the same compiler with different options (debug/release mode handeled differently).

    What you can do is explicitly raise the segfault using a signal:

    #include 
    
    int main()
    {
        raise(SIGSEGV);
    }
    

提交回复
热议问题