Christopher Smith on 1 Oct 2003 05:10:17 -0000 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [ALACPP] Why won't g++ tell me I'm dumb? |
On Tue, 2003-09-30 at 21:42, Josh Dybnis wrote: > Technically gcc is doing the right thing here. String literals aren't > actually constants. It's pretty obscure. I had to actually bust out the > standard on this. What it says is that string literals are static > arrays of type char, not const char. Attempting to modify a string > literal is "undefined", but it's not actually forbidden for an > implementation to support it. This is from the C standard, but I assume > that C++ retains this for compatibility. Out of curiosity, is this from the C89 or C99 standard? I thought the relevant section of the gcc info page would help give you guys an idea as to why Kevin and I were surprised by this behavior: `-fno-const-strings' Give string constants type `char *' instead of type `const char *'. By default, G++ uses type `const char *' as required by the standard. Even if you use `-fno-const-strings', you cannot actually modify the value of a string constant, unless you also use `-fwritable-strings'. This option might be removed in a future release of G++. For maximum portability, you should structure your code so that it works with string constants that have type `const char *'. FYI, doing "-fwritable-strings" does of course fix this problem. -- Christopher Smith <x@xxxxxxxx> _______________________________________________ alacpp mailing list alacpp@xxxxxxxxxxx http://lists.ellipsis.cx/mailman/listinfo/alacpp