[comp.lang.c] Why not portable?

levy@ttrdc.UUCP (Daniel R. Levy) (10/31/88)

In article <8795@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn ) writes:
> In article <7421@ihlpl.ATT.COM> knudsen@ihlpl.ATT.COM (Knudsen) writes:
> >In article <8775@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn ) writes:
> >> (But don't write something like
> >> 	for (p = &a[j]; --p >= a; )
> >> which is nonportable.)
> >Why not portable?
> 
> [hinty answer omitted]

The problem, plainly put, is that should a[0] be closer to the low end of its
address space than the size of an element of a, there's no such thing as a
pointer p to an object of the type of an element of a such that p is not
greater than or equal to &a[0].  What will happen then is implementation
dependent, which could be wrapping the pointer around to the high end of a's
address space, so that the loop never terminates, or catching the decremen-
tation of p when it is equal to &a[0] as a runtime fault, or if the compiler
is smart enough, complaining and not compiling the program at all.
-- 
|------------Dan Levy------------|  THE OPINIONS EXPRESSED HEREIN ARE MINE ONLY
| Bell Labs Area 61 (R.I.P., TTY)|  AND ARE NOT TO BE IMPUTED TO AT&T.
|        Skokie, Illinois        | 
|-----Path:  att!ttbcad!levy-----|