[Swan-dev] pointer initialization and fcfcde7422a4805a56a3a4a175271c56fbbbab12

D. Hugh Redelmeier hugh at mimosa.com
Mon Jul 4 21:03:24 UTC 2016

| From: Lennart Sorensen <lsorense at csclub.uwaterloo.ca>

| 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.

Almost always an int to pointer conversion involves a literal 0.  Easy.

Almost no pointers (literal or otherwise) are converted to int.

The part of the standard you quoted refers to a literal 0.

Casting a non-0 literal integer to a pointer type is rare.  Using -1
as a second in-band signal happened sometimes in old code.

Casting a non-literal integer to a pointer is not often meaningful.
Or vice-versa.  It is not common.  But it is legal.  It is usually a
sign of a broken program.  Really low-level programs may do pointer
arithmetic with some integral type.  The standard imposes no
requirements on this.

It is as easy to handle this conversion as it is to handle casting an
int to a float.  From a compiler standpoint, it takes code, not just
painting a new type on the old value.  Since this is rare, who cares?

More information about the Swan-dev mailing list