grunwald@flute.cs.uiuc.edu (Dirk Grunwald) (01/19/89)
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. Needless to say, this is what good compilers are for, particular compilers with -fstrength-reduce. 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. 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 <name> [<bounds0>][<bounds1>] etc... where <bounds0>, <bounds1> 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. [ I just took a quick survey -- three C hackers said ``yes, this is needed'' ]
mdt@YAHI.STANFORD.EDU (Michael Tiemann) (01/19/89)
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 <name> [<bounds0>][<bounds1>] etc... where <bounds0>, <bounds1> 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