C official DOD langauge?

brnstnd at stealth.acf.nyu.edu brnstnd at stealth.acf.nyu.edu
Thu Jun 7 01:52:47 AEST 1990


In article <8237 at crdgw1.crd.ge.com> volpe at underdog.crd.ge.com (Christopher R Volpe) writes:
> In article <17598:Jun611:32:2890 at stealth.acf.nyu.edu> brnstnd at stealth.acf.nyu.edu (Dan Bernstein) writes:
> >In article <1631 at dinl.mmc.UUCP> noren at 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



More information about the Comp.lang.c mailing list