Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!crdgw1!underdog!volpe From: volpe@underdog.crd.ge.com (Christopher R Volpe) Newsgroups: comp.lang.c Subject: Re: C official DOD langauge? Message-ID: <8237@crdgw1.crd.ge.com> Date: 6 Jun 90 13:00:11 GMT References: <1990May30.212533.8105@msuinfo.cl.msu.edu> <1628@dinl.mmc.UUCP> <1630@dinl.mmc.UUCP> <1631@dinl.mmc.UUCP> <17598:Jun611:32:2890@stealth.acf.nyu.edu> Sender: news@crdgw1.crd.ge.com Distribution: usa Organization: General Electric Corporate R&D Center Lines: 26 In article <17598:Jun611:32:2890@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes: >In article <1631@dinl.mmc.UUCP> noren@dinl.UUCP (Charles Noren) writes: >> C Advantage list: >> 5. Array subscripts in C must start with zero, which for >> some is counter intuitive > >But with pointers, or even with simple macros, you can trivially get >around this ``restriction.'' After #define b (&a[0] + 3), b can be used >as an array of the same size as a, starting from -3. (Hmmm: is it >guaranteed by ANSI that &a[0] - 1 + 1 equals a?) > >---Dan No, that's not guaranteed. &a[0]-1 is outside the bounds of the array, which is undefined, except when it's one object beyond the end of the array. However, that doesn't apply to your example in this case: "b[-3]" is well defined and equal to "a" because the expression becomes (&a[0]+3)[-3] , and the "+3" is done before the "-3" so you don't have to worry about going before the first element. Of course, if a has 2 elements, &a[0]+3 is overstepping the high end. (a[0] and a[1] are objects, a[2] is a legal reference to the first element beyond the high end, and a[3] is illegal. BTW, why are we saying "&a[0]" instead of "a"???) --Chris (volpecr@crd.ge.com)