Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: Array bounds checking with C???? Message-ID: <425@taumet.com> Date: 29 Aug 90 14:45:12 GMT References: <7611@ucdavis.ucdavis.edu> <869@qmfl.jrdc.go.jp> Organization: Taumetric Corporation, San Diego Lines: 22 spee@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@taumet.com