Is range(ptrdiff_t) > range(size_t)?

Doug Gwyn gwyn at brl-smoke.ARPA
Sun Jul 31 05:43:20 AEST 1988


In article <485 at draken.nada.kth.se> pk-tle at draken.UUCP (Tommy Levitte) writes:
>>Is the following relationship always true?
>>	sizeof(char a[]) == &a[sizeof(a)] - &a[0]
>No! If you use any C on a PC system, this will never be true, due to the
>segment:offset adress format.

Yes!  At least, modulo correcting the syntax of the example,
C requires the relationship to be true.

On a segmented architecture, if the array is allocated within
a single segment, it is easy to ensure this.  Otherwise, the
compiler will have to use more involved pointer operation
support, but it's still required that the difference of two
pointers into an array yield the number of array elements
between them (give or take 1).

If your compiler doesn't do this, it is broken.



More information about the Comp.lang.c mailing list