C String literals: Where do they go?
Posted
by Chris Cooper
on Stack Overflow
See other posts from Stack Overflow
or by Chris Cooper
Published on 2010-04-07T04:11:10Z
Indexed on
2010/04/07
4:13 UTC
Read the original article
Hit count: 370
I have read a lot of posts about "string literals" on SO, most of which have been about best-practices, or where the literal is NOT located in memory.
I am interested in where the string DOES get allocated/stored, etc.
I did find one intriguing answer here, saying:
Defining a string inline actually embeds the data in the program itself and cannot be changed (some compilers allow this by a smart trick, don't bother).
but, it had to do with C++, not to mention that it says not to bother.
I am bothering. =D
So my question is, again, where and how is my string literal kept? Why should I not try to alter it? Does the implementation vary by platform? Does anyone care to elaborate on the "smart trick?"
Thanks for any explanations.
© Stack Overflow or respective owner