Where is this string allocated?

Started by Gary Willoughby, December 30, 2009, 07:09:41 PM

Previous topic - Next topic

Gary Willoughby

When i define a pointer like this:


char *a = "Hello World";


Where does it place the string? On the heap?

JohnF

Quote from: Gary Willoughby on December 30, 2009, 07:09:41 PM
When i define a pointer like this:


char *a = "Hello World";


Where does it place the string? On the heap?

Normally one doesn't need to know. A string literal is held in read only memory, somewhere. Maybe someone else knows exactly where it is, I don't.

John



AlexN

Quote from: Gary Willoughby on December 30, 2009, 07:09:41 PM
When i define a pointer like this:


char *a = "Hello World";


Where does it place the string? On the heap?
If you really want to know it, you can translate you source with an option like /Tx86-asm. Then you can look in the generated assembler source in witch section your string is stored.
best regards
Alex ;)

frankie

You are creating an initialized variable, even if you use its address not its value, and is placed in ".rdata".
You can force the creation of initialized data in the code section with the compiler directive "/cbstring" normally used for drivers compilation.
You can also create your sections and place data there usinge the pragma "data_seg( [ "name" ] )".
Read the help file you'll find a lot of info.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide