Re: Books for advanced C++ debugging
"Bo Persson" <bop@gmb.dk> writes:
Michael Oswald wrote:
Stuart Redmann wrote:
On 11 Jul., 00:54, Joshua Maurice <joshuamaur...@gmail.com> wrote:
Just to add my two cents:
1. C++ lets you do everything, so chances are not bad that you can
go beyond your depth. In contrast to this, JAVA restricts your
abilities (no messing around with pointers), which makes your code
inherently safer. I think both are inferior to programming
languages like Ada95. Ada has a real type system (something that
neither C++ nor JAVA has) and will perform zounds of checks (it is
the only language I know that handles integer overflows). Since
these checks give you a lot of performance penalties, you have to
provide additional information about which checks can be omitted.
Well, I am no expert on Ada, but I had a look on Ada 2005 when
searching for other languages to learn and wrote only some simple
programs. I finally changed to Haskell and Ocaml just to learn some
new
principles of programming.
Anyway the Ada people claim, that a lot of these checks can be
optimised out by the compiler and the remaining ones are rather
inexpensive.
This was designed into the language from the beginning, so Ada arrays
know their size so you can iterate over a'range. No need to range
check.
for i in a'range loop
a(i) :=1; -- always in range
end loop;
Also, the index type can be a subtype restricted to the allowed range
of the array type. As the index then just cannot be out of range,
there is no need to check a(i).
In C++ we have it differently.
Notice that with intensive use of classes, we could archive similar results:
template <int MIN,int MAX>class Integer{
int value;
public:
Integer(int aValue){rangeCheck(MIN,MAX,aValue);value=aValue}
// operators...
};
std::vector<X> v;
for(Integer<0,v.size()-1> i=0;i<v.size()-1;i++){
v[i]; // no check needed.
}
Ok, perhaps a more intelligent compiler and some work on the syntax is
needed, but you get the idea.
Now, perhaps it might be slightly easier to write: for i in a'range...
--
__Pascal Bourguignon__