M
Michael DOUBEZ
Noah Roberts a écrit :
OK. My mistake.
Yes, it is misleading and only because K&R C (before 1988) does not have
the const keyword.
Michael
I think you've missed the point. The compiler will not complain about
code that does this:
char * x = "hello";
x[2] = 't';
You'll only get a warning when you try to run the program...if
then...maybe only when you create your release compile with its
optimizations...maybe a customer will find it.
The standard requires that this is ok. It is undefined, even in C where
it comes from, but there can be no diagnostic. Most people would like
to get the usual error about attempting to assign const to non-const
without a cast, but you don't get that in this one special case. Allows
for all sorts of unfortunate errors.
OK. My mistake.
Yes, it is misleading and only because K&R C (before 1988) does not have
the const keyword.
Michael