Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In the C99 standard, §7.17.3 states that <code>NULL</code> “expands to an implementation defined <em>null pointer constant</em>”. Meanwhile §6.3.2.3.3 defines <em>null pointer constant</em> as “an integer constant expression with the value 0, or such an expression cast to type <code>void *</code>”. As there is no other definition for a null pointer constant, a conforming definition of <code>NULL</code> must expand to an integer constant expression with the value zero (or this cast to <code>void *</code>).</p> <p>Further quoting from the <a href="http://c-faq.com/null/machnon0.html" rel="nofollow noreferrer">C FAQ question 5.5</a> (emphasis added):</p> <blockquote> Section 4.1.5 of the C Standard states that NULL “expands to an implementation-defined null pointer constant,” which means that the implementation gets to choose which form of 0 to use and whether to use a `void *` cast; see questions 5.6 and 5.7. “Implementation-defined” here <strong>does not mean that NULL might be #defined to match some implementation-specific nonzero internal null pointer value</strong>. </blockquote> <p>It makes perfect sense; since the standard requires a zero integer constant in pointer contexts to <em>compile</em> into a null pointer (regardless of whether or not the machine's internal representation of that has a value of zero), the case where <code>NULL</code> is defined as zero must be handled anyhow. The programmer is not required to type <code>NULL</code> to obtain null pointers; it's just a stylistic convention (and may help catch errors e.g. when a <code>NULL</code> defined as <code>(void *)0</code> is used in a non-pointer context).</p> <p>Edit: One source of confusion here seems to be the concise language used by the standard, i.e. it does not explicitly say that there is no <em>other</em> value that might be considered a null pointer constant. However, when the standard says “…is called a null pointer constant”, it means that <em>exactly</em> the given definitions are called null pointer constants. It does not need to explicitly follow every definition by stating what is non-conforming when (by definition) the standard defines what <em>is</em> conforming.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload