POV-Ray : Newsgroups : povray.off-topic : Quick C language-lawyer question... : Re: Quick C language-lawyer question... Server Time
5 Sep 2024 11:22:16 EDT (-0400)
  Re: Quick C language-lawyer question...  
From: clipka
Date: 30 Jul 2009 18:15:01
Message: <web.4a721ad85e1da091a13874630@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> By my reading, neither C nor C++ guarantee the following:
>
> union {
>    long x;
>    char* y;
> } xyz;
> xyz.y = NULL;
> printf("%ld\n", xyz.x);
>
> Neither C nor C++ guarantees that'll be zero (assuming
> sizeof(char*)==sizeof(long)).  In other words, neither guarantees that the
> bit pattern in memory for NULL is actually all zeros, right?

Absolutely right. Although it is common on most architectures to use an all-zero
value to represent a null pointer value, the specification only requires that
the binary representation is not used for any other purposes.

Just as you cannot rely on the char type to be an 8-bit integer. Or pointers to
be of the same size as long int, for that matter.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.