NULL question not in FAQ

Doug Gwyn gwyn at smoke.brl.mil
Fri Mar 29 08:10:20 AEST 1991


In article <1991Mar27.194101.1685 at grebyn.com> ckp at grebyn.com (Checkpoint Technologies) writes:
>	int i = 0;
>	char *p = (char *)i;
>So is it correct to interpret this code as unportable?

It's not only not guaranteed to work in all standard-conforming C
implementations, it may not even compile successfully, if "int" is
not a suitable type for holding a pointer representation.  (SOME
integer type must do so, but not necessarily "int", which for example
could be only 16 bits in a 24-bit address-space environment.)

Basically, you should try to not use integer types to hold values of
pointers.  Usually it is simpler to use a pointer type all along.



More information about the Comp.lang.c mailing list