Re: where is the string literal allocated ? On the stack ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Michael Gong wrote:
Though it's not related with gcc, could anyone help me with following question:

Where is the string literal allocated ? Is it on the stack ?

For example, where is "abc" allocated ?

char * foo() {
   return "abc";
}

It can't be on the stack in this case, because if it was, it would cease to exist when foo() returns.

AFAIK string literals all live in the read-only data segment (.text?).

(Your prototype is wrong, btw; you are casting a const char * that lives in read-only memory to a char *, which is just *ASKING* for your program to SEGV at some point.)

--
Matthew
<insert bad pun... on second thought, better not>


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux