Problem with the string

John (Eljay) Love-Jensen eljay@adobe.com
Fri Nov 24 18:45:00 GMT 2006


Hi kanishk,

> i want to put string "kanishk" into writeable memory (or other than read execute segment). Is there a way for doing this without making any change in calling sequence (for example it may be regulated by some switch in gcc) or there is no provision in C99 standard for it.

The 'string "kanishk"' is a read-only non-modifiable C-string literal constant.

Are you programming in C or C++?  Then a read-only non-modifiable C-string literal constant is read-only and non-modifiable.  There is no provision in C or C++ to make a read-only non-modifiable C-string literal constant into a non-read-only modifiable C-string literal mutable.

If you want a modifiable string, you have to declare it that way, for example:

char kanishk[] = "kanishk";
MyFuncThatModifiesTheCharPtrData(kanishk);

(Hopefully the MyFuncThatModifiesTheCharPtrData doesn't overrun the buffer.)

HTH,
--Eljay



More information about the Gcc-help mailing list