[Swan-dev] pointer initialization and fcfcde7422a4805a56a3a4a175271c56fbbbab12
lsorense at csclub.uwaterloo.ca
Mon Jul 4 17:24:05 UTC 2016
On Sat, Jun 25, 2016 at 10:24:15PM -0400, D. Hugh Redelmeier wrote:
> This commit is technically wrong. I admit that the problem will not show
> up on most machines.
> The C standard does not require that the binary representation of a NULL
> pointer be 0. Initializing a struct by zeroing bytes does not guarantee
> that pointer fields are initialized to NULL.
C11 does require that in fact.
It states (in section 184.108.40.206.3):
An integer constant expression with the value 0, or such an expression
cast to type void *, is called a null pointer constant. 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.
And I have never heard of an implementation that didn't do that.
Doing otherwise made things like "if (!pointer) ..." too damn hard to
More information about the Swan-dev