Converting FORTRAN to C

Norman Diamond ndiamond at watdaisy.UUCP
Thu Jan 3 04:26:22 AEST 1985


> There is at least one excellent reason, commonly used in C, for referencing
> beyond the bounds of an array.  It is this:
> 
> #define	ARRAYSIZE	200
> 
> type_t array[ARRAYSIZE];
> 
> ...
> 
>     type_t *p;
> 
>     for (p = array; p < &array[ARRAYSIZE]; p++)
> 	...

&array[ARRAYSIZE] does not reference any part of the array.  However, after
the loop is exited due to the stated condition, if code dereferences p (i.e.
uses *p), THEN the code is referencing beyond the array bounds and is broken
and should not be of concern to language translators.

-- Norman Diamond

UUCP:  {decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdaisy!ndiamond
CSNET: ndiamond%watdaisy at waterloo.csnet
ARPA:  ndiamond%watdaisy%waterloo.csnet at csnet-relay.arpa

"Opinions are those of the keyboard, and do not reflect on me or higher-ups."



More information about the Comp.lang.c mailing list