* Nitin Bhardwaj:
It is said that C++ is a strongly typed language and thus a type-safe
language (unlike C).
That is incorrect.
However, C++ supports type-safety in more ways than C.
So it's possible to program in C++ in (more or less) type-safe ways.
So how does one explain the following behaviour :
int main(void)
{
char *p = NULL;
p = "A String Literal";//the compiler isuues no error/warning here
// but ideally it should...as p is a non-const
// pointer and the string literal has the type
// const char *
// So, a conversion from const-ptr TO non-const
// should elicite warning/error from the compiler !!
return 0;
}
I've tried it on both MSVC++ 6 compiler on Windows 2000 ( Intel P IV )
and GNU C++ compiler gcc 3.x RedHat GNU\Linux ( Intel P IV )
It's backward compatibility with C.
There are other far more horrendous compatibility-derived issues.
For instance, automatic conversion of array type to pointer type and
treating pointers as arrays, in the context of an array of objects.
On the other hand, in some respects C++ is more type-safe than e.g.
Java.
For example, template support enables static type-checking in many
situations where it's not possible in (old non-generic) Java; C++ har
more stringent type-checking (although not 100%) at link time; C++
constructors enforce class invariants while Java constructors do not.
--
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?