Array bounds checking with C????

Richard Tobin richard at aiai.ed.ac.uk
Fri Aug 31 22:11:30 AEST 1990


In article <988 at christopher-robin.cs.bham.ac.uk> cjr at christopher-robin.UUCP (Chris Ridd <RiddCJ>) writes:
>>I had heard it still objected to `&arr[sizeof arr/sizeof *arr]',
>>which is Officially Legal.

>  Why is this?  I never could figure out why accessing the first
>element *past* the end of an array should be legal.

Because it's not *accessing* it.  Note the ampersand.

It's very useful for loops:

    for(p = buf;  p < &buf[sizeof(buf)];  p++)

-- Richard
-- 
Richard Tobin,                       JANET: R.Tobin at uk.ac.ed             
AI Applications Institute,           ARPA:  R.Tobin%uk.ac.ed at nsfnet-relay.ac.uk
Edinburgh University.                UUCP:  ...!ukc!ed.ac.uk!R.Tobin



More information about the Comp.lang.c mailing list