From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,dab7d920e4340f12 X-Google-Attributes: gid103376,public From: mab@dst17.wdl.loral.com (Mark A Biggar) Subject: Re: C is 'better' than Ada because... Date: 1996/07/16 Message-ID: <4sgakm$kcu@wdl1.wdl.lmco.com>#1/1 X-Deja-AN: 168510316 references: <31E4DC46.794BDF32@mailgw.sanders.lockheed.com> <31E57A6C.3F2E@csehp3.mdc.com> organization: Loral Western Development Labs newsgroups: comp.lang.ada Date: 1996-07-16T00:00:00+00:00 List-Id: In article nasser@apldbio.com (Nasser Abbasi) writes: > What about the lack of any boundary checking at all? >James make good points ofccourse, but I think the view that C++ >programmers would have is that some of the above could be fixed >by using classes instead of the primitive language data types. At least >to the point of boundary checking. As an example, one would use >an array class instantiated to the correct type and the size of the >array, where this class would throw an exception (or do an assert) if >the index is out of bounds. SOmething like this: >---------------------------------------------- >template< class type, int dimension> >class array >{ > .... > type operator[] ( int index) > { > if( index >= dimension || index < 0 ) > throw ... some object as the exception > // or assert ( index < dimension && index >=0); > // all clear now , index is within range, get the index data > return data[index]; > } > private: > type data[dimention]; >}; >-------------------------------------------- >and one would then create objects of this class as >array a; // now a is array of int 0..9 >array b; // array of chars 0..99 >.. >now writing this > int i = a[11]; // should throw an exception >So, in C++ it seems that one can say, if there is something not >right in the core langauge, one can use the core language to fix >this problem, as the example above show, one uses C++ to fix >the fact that C++ do not have boundary range checking. >The problem I see with this is that this addes a layer of >software between the application/usr and the core langauge, in >the above example, this layer is the array class software, so >would would then use this class to make arrays instead of using >the array construct avaliable in the core language. In addition the above code make it almost impossible to optimize out unnecessary checks. The empirical evidence is that only about 10% of array bounds checks are really necessary, assuming that you can declare index variables that are limited in range to the array bounds, but you can't so that either in C (you can in C++, but that adds yet another layer of possible redundant checks that you can't easily optimize away.) -- Mark Biggar mab@wdl.lmco.com