Do C and C++ standards imply that a special value in the address space must exist solely to represent the value of null pointers?

后端 未结 4 1547
猫巷女王i
猫巷女王i 2021-01-27 08:08

Following discussion from this question about null pointers in C and C++, I\'d like to have the ending question separated here.

If it can be inferred from C and C++ stan

4条回答
  •  庸人自扰
    2021-01-27 08:36

    Yes, that's precisely what it means.

    [C++11: 4.10/1]: [..] A null pointer constant can be converted to a pointer type; the result is the null pointer value of that type and is distinguishable from every other value of object pointer or function pointer type. [..]

    The null pointer value doesn't need to be 0x00000000, but it does need to be unique; there's no other way to make this rule work.

    It's certainly not the only rule of the abstract machine that implicitly emplaces strict limitations upon practical implementations.

    What if the OS puts a really useful function or data structure at the same address that's equal to nullptr?

    The OS won't do that but it can be exploited.

提交回复
热议问题