From: Aidan Kehoe (kehoea at domain parhasard.net)
Date: Thu 13 Sep 2001 - 15:14:43 IST
Ar an 13u la de mi 9, scriobh Padraig Brady :
> An interesting gotcha those const strings. I.E. if you declare.
> char* string="This can't be modified";
> string[0]='t'; /* seg fault */
> Note allowing this can be quite useful and is sometimes assumed
> (especially by older code) and so some compilers allow it by default.
> With gcc you have to explicitly allow it using -fwriteable-strings
-traditional allows it, too. It does mean that that funky optimization
where the compiler looks for strings that are identical to machine
code and uses the strings instead of including the machine code can't
be used anymore. Not that that was ever gonna make a *huge*
difference, anyway.
> Note finding this error can be hard when you cast/pass pointers
> to these const string around and so gcc gives another option:
> -Wwrite-strings (which isn't included by -Wall) to help you.
> anyway getting back on topic...
Heh, there was a topic? Oh yeah, Michael Tracy's Segmentation Fault.
-- `... when the elephant man broke strong men's necks, when he'd had too many Powers, ...'
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:12:08 GMT