Is using an invalid pointer value legal in C?

后端 未结 3 775
长发绾君心
长发绾君心 2021-01-14 19:59

The following code is undefined behavior in C++ (although it will work okay on almost any widely used implementation):

int* pointer; //uninitialized - likely         


        
3条回答
  •  礼貌的吻别
    2021-01-14 20:36

    It's undefined behavior in C as well because on certain architectures, loading an invalid pointer into a register triggers a hardware fault.

    See Is storing an invalid pointer automatically undefined behavior?

提交回复
热议问题