Does Standard define null pointer constant to have all bits set to zero?

前端 未结 4 764
北恋
北恋 2020-12-07 05:27

( I\'m quoting ISO/IEC 9899:201x )

Here we see that, integer constant expression has an integer type:

6.6 Constant expressions

6. An in

4条回答
  •  佛祖请我去吃肉
    2020-12-07 05:39

    No, NULL doesn't have to be all bits zero.

    N1570 6.3.2.3 Pointers paragraph 3:

    An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. 66) If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.

    See my emphasis above: Integer 0 is converted if necessary, it doesn't have to have same bit presentation.

    Note 66 on bottom of the page says:

    66) The macro NULL is defined in (and other headers) as a null pointer constant; see 7.19.

    Which leads us to a paragraph of that chapter:

    The macros are

    NULL

    which expands to an implementation-defined null pointer constant

    And what is more, on Annex J.3.12 (Portability issues, Implementation-defined behaviour, Library functions) says:

    — The null pointer constant to which the macro NULL expands (7.19).

提交回复
热议问题