From: "Chris A. Triebel" Newsgroups: comp.os.msdos.djgpp Subject: Re: array-bound-checking Date: Thu, 19 Sep 1996 08:19:08 -0400 Organization: University of New Hampshire - Durham, NH Lines: 33 Message-ID: References: <17B73660C60 AT fs2 DOT mt DOT umist DOT ac DOT uk> NNTP-Posting-Host: sun4.iol.unh.edu Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: <17B73660C60@fs2.mt.umist.ac.uk> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp On Thu, 19 Sep 1996, A.Appleyard wrote: > (2) One thing that I miss in C is optional array-bound-checking like I found > so useful in Algol-like languages and even in primitive `autocodes' for > mainframes long before there were desktop computers; that facility quickly and > easily spotted many out-of-bounds store accesses that in C programs are often > the devil's own job to track down. Is putting an array bound in these C or C++ > constructions forbidden, or is it allowed but ignored?:- > int zxcvbnm(int n,double x[n]) { ...... } > double *x[n+2]; > If it is allowed, it would provide a way to specify size of parametric and > pointed-to arrays for a possible array-bound-check compiler option. I think that it goes against C and C++ grain to do things like that. It takes time to do the checking and reduces flexibility in some ways. If my history lessons are correct C was developed to be as fast as possible, and to leave as small a footprint as possible. It has been left to the programmer to determine what checks are done and how to set them up. But there is a way to do this and a whole lot more. Use C++, create or have created a template class which will contain an array of any type and put the necessary bounds checking code in there. Classes are just a fancy TYPE, like int, char, etc ... They can generally be made very flexible at the expense of speed/size. If I remember correctly djgpp has a bunch of template classes in the library, but I never looked at or used them. I tend to write my own when I need it. You sound like you need a general form of class, so maybe the distributed stuff will be applicable. The only requirement to the above is that you would need to use C++. Hope I've been of help cat