Path: utzoo!telly!ddsw1!mcdchg!rutgers!tut.cis.ohio-state.edu!YAHI.STANFORD.EDU!mdt From: mdt@YAHI.STANFORD.EDU (Michael Tiemann) Newsgroups: gnu.gcc Subject: Bounds checking for array references Message-ID: <8901181903.AA20415@yahi.Stanford.EDU> Date: 18 Jan 89 19:03:56 GMT References: Sender: daemon@tut.cis.ohio-state.edu Reply-To: tiemann@lurch.stanford.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 51 Date: 18 Jan 89 16:50:45 GMT From: uxc!garcon!flute.cs.uiuc.edu!grunwald@csd4.milw.wisc.edu (Dirk Grunwald) Organization: University of Illinois, Urbana-Champaign Sender: info-gcc-request@prep.ai.mit.edu It used to be that macho C and C++ programmers would automatically convert any array-striding code into a pointer-following mess, in the name of efficient code. Sad, but true. Needless to say, this is what good compilers are for, particular compilers with -fstrength-reduce. That's right! One of my biggest beefs with C++/C is that there is NO WAY to check array reference indicies automatically, even if you're using array indicies. I can understand your argument against C, but not against C++. In general, you don't always know the size of the array, however, often, you *do* know the size of the array, either at run-time or compile time. What I'm proposing is yet another addition to the wish list: array bounds checking and bounds specification. Bounds checking is simple: if you know the size of the array at compile time, just check the array index. Bounds specification is tricker: If there isn't a general format, I would propose #pragma array bounds [][] etc... where , etc can be expressions, not just constants. This bounding information could also be passed to GDB via the symbol table. Obviously, this isn't a cure-all for older code, but for paranoid people who write new code & want it to be easier to debug, I'd really like to see this. People who write new code should think about using C++. [ I just took a quick survey -- three C hackers said ``yes, this is needed'' ] Of course three C hackers would say "yes, this is needed". If you asked three C++ hackers, they would tell you "define an array class and use it--the language was designed to solve such problems". Michael