This is the mail archive of the gcc-help@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]

RE: Problem with the string


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


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