This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Removing -frwitable-strings
On Dec 19, 2003, at 12:02 PM, Joseph S. Myers wrote:
On Fri, 19 Dec 2003, Syd Polk wrote:
The problem with just removing this flag is that there is no
compile-time indication of the faulty code, and the bug may be a
little-used path, and the developer who has to track it down may not
even know anything about it.
-Wwrite-strings is a very good compile-time indication of the faulty code
- you may need to add lots of consts when you first use it, but if you
succeed in making the code const-correct with -Wwrite-strings -Wcast-qual
then you _probably_ don't have many problems of this type (functions such
as strchr could mask them) while if you fail then the failure will
probably lead you to the fault.
Cool.
I spent several days tracking one of these down once. I had not been
aware of gcc's default behavior.
How could we make it more likely that people in future who are in a
similar position to that you were in then will have read the manual;
specifically, the section "Incompatibilities" that explains that strings
are readonly; or the comp.lang.c FAQ, which also mentions the issue?
Make -Wwrite-strings on by default. Otherwise, people who port to gcc for the first time (like me when this happened) won't see it. To be honest, I don't know where this "Incompatibilities" section is. There is tons of documentation on gcc, so much as to be daunting. At the time when I did this port, I would just try things until they stumped me, and then I would ask coworkers where they went for documentation. Since Visual C++ and Metrowerks CodeWarrior both allowed writable strings at the time, I was not aware of this behavior.
Syd Polk
Apple Computer
Technology EPM, Mac OS X Development Tools
+1 408 974-0577