Newsgroups: comp.lang.c
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: array[-1] -- permitted?
Message-ID: <1988Sep24.211146.26484@utzoo.uucp>
Organization: U of Toronto Zoology
References: <867@osupyr.mast.ohio-state.edu> <3200@geac.UUCP> <1430@ficc.uu.net> <1988Sep19.164701.11136@ateng.uucp> <2583@ingr.UUCP> <1237@imagine.PAWL.RPI.EDU> <69575@sun.uucp>
Date: Sat, 24 Sep 88 21:11:46 GMT

In article <69575@sun.uucp> swilson@sun.UUCP (Scott Wilson) writes:
>I'm not quite sure what is being discussed.  I assume the standard
>says that the -1'th element on an array is not guaranteed to be
>accessible, not that negative array indices are disallowed...

More precisely, what it says is that even *computing* a pointer to the
-1th element of an array can send you off into the Twilight Zone.  This
is not new -- if you read K&R, that's always been the rule.  However,
there is no objection to subtracting 1 from a pointer that already points
to the Nth element of an array, where N > 0.  (&a[1])[-1] is legal.
-- 
NASA is into artificial        |     Henry Spencer at U of Toronto Zoology
stupidity.  - Jerry Pournelle  | uunet!attcan!utzoo!henry henry@zoo.toronto.edu