"kumar" <raman.emb@gmail.com> wrote in message news:
> hi
> i want to know where & how the C variables gets stored
> i mean like volatile , pointer and string variables gets stored ,
> whether it is on stack or some other places
> if is there any clear document , plz suggest the link
>
In C you have a stack and a heap. When you call a function, local variables
are pushed on the stack. The return address might also be pushed on the
stack, or there might be a special stack for it.
When you call malloc() you take a chunk for memory from the heap. This
doesn't get reused automatically, and persists until you explicitly call
free().
pointers are just ordinary variables. There's no special storage space for
them.
Global variables go into a special area of memory created at program
startup. They persist for the entire life of the program. Local variables
with "static" are really global variables in disguise. They also persist the
entire life of the program, and are stored in the same place as the globals.
However be aware that optimisers can produce any code whatsoever, as long as
it has the same effect as the code you would "naturally" expect from a
translation of C into assembly. So variables might be kept in registers, or
optimised away entirely, or funny things might be done to make cache usage
more efficient.
volatile variables can be modified outside the C program. So all these
optimisations have to be turned off. A volatile variable will always be kept
in the same place in memory so the outside routine - usually an interrupt -
can find it to modify it.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm