This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Modification of literal strings
- From: "David W. Stockton" <stockton at bcm dot tmc dot edu>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 04 Nov 2002 20:58:35 -0600
- Subject: Modification of literal strings
- Organization: Baylor College of Medicine
I am not sure if I am e-mailing the right place but I just spent about 2
hours reading FAQs
and searching the GCC web-site and cannot find the answer I need so I
thought I would
try sending it to you... if there is a more appropriate place please
let me know and I will
ask there.
I am porting a set of code to Mac OS X 10.2 that modifies some literal
strings... this causes
a bus error. I have tried this code as an example:
#include <stdio.h>
void DoThis( char *str ) {
int i;
printf( "Entry string is \"%s\"\n", str );
fflush( stdout );
for( i = 0; str && str[i]; ++i )
if( str[i] == ' ' ) str[i] = '_';
printf( "Modified string is \"%s\"\n", str );
fflush( stdout );
}
int main( int argc, char **argv ) {
DoThis( "Hello World" );
return 0;
}
Under DJGPP it runs without difficulty with the expected output.
Under Mingw32 and Cygwin it Segmentation faults after printing the
Entry string...
Under Mac OS X 10.2 / Darwin it dies with a Bus error.
Is there a compile time option or modification to the specs file
to make literal not readonly so this code runs on all the platforms?
Thanks,
David Stockton
stockton@bcm.tmc.edu