Is &a[NTHINGS] legal

Chris Torek chris at mimsy.UUCP
Sat May 7 18:42:16 AEST 1988


In article <1788 at akgua.ATT.COM> brb at akgua.ATT.COM (Brian R. Bainter) writes:
>Taking into consideration that a is an address and NTHINGS is an
>offset to that address, there should be no problem whatsoever with
>this construct.

There are more hosts in heaven and earth, B.B., than are dreamt of
in your philosophy.  (Funny wording to make the syllables come out
right.  `B.B.' is only two syllables, but the accents fix that :-) .)

>C ... does not make any limit checks for arrays.

There is no such promise in the language.  An implementation is free
to check.  It is true that most do not, as this tends to worsen benchmark
numbers, and hence does little for sales.

>If you have a question with something like this, it may be most
>worthwhile to write a test program and try the construct or algorithm
>out.

While this remains good advice, remember that this provides only one
existence proof for a single implementation.  Hence you can say with
utter certainty that at least one C compiler simply adds an offset to
a base.  As it turns out, others do something different.  Fortunately
&a[NTHINGS] is legal by definition (or fiat, as it were), according
to the dpANS.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list