|
From: Abhijit S. <mu...@gm...> - 2002-06-14 17:13:55
|
I was just going through the sources of the class libraries in Turbo C++
version 3.0, and found this code. How does the program modify aPtr even
though it says it's a const?
-------CLASSLIB/SOURCE/STRNG.CPP------
String::String( const char *aPtr )
{
if ( aPtr == 0 )
aPtr = "";
len = strlen( aPtr ) + 1;
theString = new char[ len ];
CHECK( theString != 0 );
strcpy( theString, aPtr );
}
--------------------------------------
After seeing this, I tried compiling the following file in MingW, and it did
(with -Wall, no warnings)
--------------------------------------
void do_stuff(const char *buf)
{
if(!buf)
buf = "";
}
int main()
{
do_stuff(0);
return 0;
}
--------------------------------------
How? Doesn't
buf = "";
translate to assign "" to buf?
--------------------------
http://mudeth.tripod.com
|