[ILUG] Segmentation Fault
kehoea at parhasard.net
Thu Sep 13 15:14:43 IST 2001
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='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*
> 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, ...'
More information about the ILUG