[Swan-dev] pointer initialization and fcfcde7422a4805a56a3a4a175271c56fbbbab12
lsorense at csclub.uwaterloo.ca
Mon Jul 4 20:20:16 UTC 2016
On Mon, Jul 04, 2016 at 03:15:17PM -0400, D. Hugh Redelmeier wrote:
> Let me be clearer. A pointer value that is null must test equal to
> zero. Not true of the raw bytes of a null pointer (no conversion
> happens when you deal with the raw bytes of a pointer).
> void *p;
> passert(NULL = 0); /* must not fail */
> memset(&p, 0, sizeof(p));
> passert(p == 0); /* may fail */
> p = 0;
> passert(p == 0); /* must not fail */
> static const unsigned char zeros[sizeof(void *)];
> p = 0;
> passert(memcmp(&p, zeros, sizeof(void*)) == 0); /* may fail */
> Some machines with segmented memory take advantage of this liberty.
> But most of those have died out.
So did their compiler explicitly handle a cast of a 0 value integer to
a pointer and map it to the "correct" null pointer address value?
That seems horribly complicated to manage.
More information about the Swan-dev