how has C bitten you? (Really,
Henry Spencer
henry at utzoo.UUCP
Sun Sep 8 09:36:12 AEST 1985
> Exactly, but also consider what K&R says in section 7.14:
>
> The compilers currently allow a pointer to be assigned to an integer, an
> integer to a pointer, and a pointer to a pointer of another type. The
> assignment is a pure copy operation, with no conversion.
Note that they do not say that this is a legitimate feature of the language!
All they say is that the current compilers will let you get away with it.
This is no longer generally true, by the way. K&R is quite old.
> Also, in section 14.4:
>
> A pointer may be converted to any of the integral types large enough to
> hold it. [...] The mapping function is also machine dependent, but is
> intended to be unsurprising to those who know the addressing structure
> of the machine.
>
> Although this does not seal it up completely, it seems that K&R had it in
> mind that putting pointers into integers (and taking them back again) would
> have no overhead....
True, but there is a subtle point here: they say you can convert pointers
to (sufficiently large) integers, they may say that you can convert the
result back, but they don't say what the integer will look like. A NULL
pointer will not necessarily show up as an integer zero. The equality
between NULL pointers and 0 works only when 0 is a literal constant, in
which case it is (potentially) treated specially by the compiler when
encountered in a "pointer" context. The conversion of literal 0 to the
NULL pointer is *not* an instance of the general "putting pointers into
integers (and taking them back again)" conversion.
--
Henry Spencer @ U of Toronto Zoology
{allegra,ihnp4,linus,decvax}!utzoo!henry
More information about the Comp.lang.c
mailing list