C official DOD langauge?

Christopher R Volpe volpe at underdog.crd.ge.com
Wed Jun 6 23:00:11 AEST 1990


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:
>> 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 at crd.ge.com)



More information about the Comp.lang.c mailing list