Oh, sorry, typo. I meant array.
A dynamic array is stored on the heap; a static array is stored on the stack.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
A constant string such as this is stored in static memory (along with any static and global variables).I don't believe there is any rule for where "The Empire Strikes Back" must be stored
Originally Posted by sigfriedmcwild
WHOA!!! I just had to put my two cents in while reading this thread, then i saw all the gurus' already tore into you.
ouch. Hope you figured it out now, if not search the board, you'll find tons on schooling on the difference.
was the authour of your book named herbert schildt by the way?I said that an array is a pointer because that's what I've read in at least 2 books. I guess they just glossed over the important details.
Sorry about that
Last edited by caroundw5h; 12-22-2004 at 10:32 PM.
Warning: Opinions subject to change without notice
The C Library Reference Guide
Understand the fundamentals
Then have some more fun
But if they're stored in the same place as globals and static variables, which are modifiable, then where does this stuff about read-only memory come from? It makes sense if it's stored in the same way as const variables, but I just don't see it happening with globals.A constant string such as this is stored in static memory (along with any static and global variables).
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Sorry, I misspoke. I should have said that a string such as "The Return of the Temple of Doom" is stored in constant memory alongside static memory where static and global variables reside. If you would be so kind, pardon my zinger.
>>is stored in constant memory alongside static memory
Maybe I should read a book about this So the constant memory block is adjacent to the static memory block, and string literals are stored in the constant memory block, while globals/statics are stored in the static memory block.
Did I get it this time?
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
The only requrement for a string literal is that it exist at the time of instansiation. Thus char *s="This is a string?"; s must contain the address of consecutive characters containing the string. The normal way this is done, and this is just an implementation issue, is that the string is contained within the code segment. Beause the instructions must be loaded before execution can begin, and string literals are often requred very early in program execution it makes sense to load these strings with the instructions. On modern computers memory is devided into pages, and some of these pages have different attributes. Pages that contain instructions don't change, so the processor tags them as read only. This lets the processor have two cache mechanisms, a write back and complicated cache for data and a much simpler cache for instructions. As self-modifiying code is frowned upon making this cache read-only saves a lot of effort.