This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
writeable-strings (gcc 4 and lower versions) clarification
- From: "sting sting" <zstingx at hotmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sat, 23 Apr 2005 10:35:09 +0300
- Subject: writeable-strings (gcc 4 and lower versions) clarification
- Bcc:
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/