Re: C++ : protections and freedom...
* kk:
I am trying to compile a list of items in the C++ language where it
offers some protections from the compiler that prevent the user from
making mistakes and in other areas total freedom to do what you want at
your own risk. For example, I would say the const keyword is an
overloaded keyword that offers protection on various fronts like const
variables(compiler prevents you from accidentally modifying these
variables), const member functions( compiler prevents you from
accidentally modifying the object on which the method is invoked), the
dynamic_cast ( a mechanism through which you can check the safety of
you casting operation), encapsulation through use of scope modifiers to
prevent users from accidentally modifying private data, etc.
On the other hand, the freedom to do anything at your own risk is
provided by way of the ability to directly access raw memory through
pointers, usage of reinterpret_cast to cast one type to a different
type, placement new and delete to specifically play around with
memory, etc.
Need help to compile more of these.
The greatest and first protection in C++ is strong static type checking,
across compilation unit, which was added on top of C.
Note that Java, touted as a much safer language than C++, does not have
full strong static type checking across compilation units. At least,
Java didn't have that strong, global static type checking four or five
years ago. Who knows what it has today.
The greatest freedom in C++, as in C, is the use of pointer arithmetic
and void pointers.
However, there is a third category which might be much more interesting
in the end.
Namely the areas where current C++ supports the compiler's possible
1970's style optimization, to the detriment of well-defined'ness,
essentially trading correctness for no faster execution (because that's
the practical result today); one primary example is the free order of
evaluation for arguments to most built-in operators.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?