This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

writeable-strings (gcc 4 and lower versions) clarification


Hello,

If you will comple with gcc (version lower than 4) a program like this , on Linux:

int main()
    {
     char* myString = "test";
    (*myString)++;

}

You will get a segfault when running it.
On the other hand, if you will pass -fwriteable-strings at compilation ,
you will be able to run it without any segfault .
They do say in the man gcc that writeable-strings is deprecated and it is better not to
use it.


According to gcc-4.0 docs,
"GCC no longer accepts the -fwritable-strings option. Use named character arrays when you need a writable string."


see
http://gcc.gnu.org/gcc-4.0/changes.html

I have 2 questions:

What are the disadvantages of using -fwritable-strings and why was it removed ?


by "Using named character arrays" I assume that the meaning is writing char myString[] = {"test"};

am I right ?

Regards,
Sting

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]