Array bounds checking with C????

Stephen Clamage steve at taumet.com
Thu Aug 30 00:45:12 AEST 1990


spee at qmfl.jrdc.go.jp (Paul SPEE) writes:

>To be able to check the array boundaries, the C compiler must now the
>array size. However, in most important cases the C compiler does not
>have this information. This can be either be the case when an array
>is passed as a function parameter or is allocated as a dynamic array.
>It would have been convenient if ANSI would have allowed 'pointers
>to variable size arrays'. For example,

There is nothing to prevent the C compiler from carrying around enough
information with arrays and pointers to detect those problems at runtime
which cannot be found at compile time.  Such a compiler could still be
ANSI-conforming.  When an array was declared, the compiler would
allocate extra space, say, just before the beginning of the array to
contain size information.  Pointers would be larger than a plain address
to contain similar information.  Every array reference and pointer
dereference would then be checked for bounds violation, at compile time
if possible, at run time otherwise.  This approach is in fact implemented
in some compilers.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list