various forms of nil
Chris Torek
chris at mimsy.UUCP
Sat Aug 12 15:50:30 AEST 1989
>In article <18996 at mimsy.UUCP> I suggested that
>> int *ip = (int *)(char *)0;
was not portable.
In article <1447 at cbnewsl.ATT.COM> dfp at cbnewsl.ATT.COM (david.f.prosser) writes:
>The pANS does guarantee that, for example,
> 0 == (void *)(int *)(char *)0
>[3.2.2.3: "Two null pointers, converted through possibly different sequences
>of casts to pointer types, shall compare equal."]
>
>Therefore, I interpret the pANS as requiring
> (int *)(char *)0
>to have the same value as
> (int *)0
>(the nil-pointer-to-int, in your terminology)--not `just happening' to work.
It does seem to say this. I missed this clause earlier. I find it
somewhat astonishing, actually. It makes carrying types around with
each nil pointer value rather difficult. (It would be nice for, e.g.,
a debugger to be able to say
location arr[300] contains (struct foo *)0
but the only way to do this is to have a different value for every kind
of nil, and this clause would then constrain pointer comparisons and/or
casts to `look past' the difference. Being able to tell what kind of
object---nil pointer or otherwise---resides in some memory location
would be of some use in tracking down stray-pointer bugs. Then again,
to do this right requires type tags everywhere, not just for nil pointers.)
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list