Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!yale!cmcl2!stealth.acf.nyu.edu!brnstnd From: brnstnd@stealth.acf.nyu.edu Newsgroups: comp.lang.c Subject: Re: C official DOD langauge? Message-ID: <18606:Jun615:52:4790@stealth.acf.nyu.edu> Date: 6 Jun 90 15:52:47 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> <8237@crdgw1.crd.ge.com> Reply-To: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Distribution: usa Organization: IR Lines: 30 In article <8237@crdgw1.crd.ge.com> volpe@underdog.crd.ge.com (Christopher R Volpe) writes: > 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: > >> 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?) > 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. In that case, numbering an array from 1 or any other positive number by the above method is not ANSI compliant, though it will work on any real machine. Numbering it from x through y, where x is negative and y is at least -1, is both portable and fully compliant. If you don't care about such syntactic purity then #define b(i) (a[i - x]) does the job in all cases. > However, that doesn't apply to your example > in this case: "b[-3]" is well defined and equal to "a" I know, but I was worrying about the opposite case. > BTW, why are we saying "&a[0]" instead of "a"???) To help the Fortran and Pascal types at whom this thread is directed. ---Dan