Re: Static Variables



please don'e top-post. Put your reply below what you are
replying to, better yet intersperse your reply amongst
the original post. I have re-arranged your post.

On 20 Feb, 10:01, akm.sat...@xxxxxxxxx wrote:
Ian Collins wrote:
akhil.mi...@xxxxxxxxx wrote:

where does a static variable inside a function get stored?? where does
it go in memory?? like Global goes in RAM, Local variable goes on
Stack... but how does static variable takes place in memory??

Stack *is* RAM.


It's an implementation issue. If the detail is important for your
application, consult your compiler's documentation.

--
Ian Collins

please remove sigs (the bit after --<space>)


Compiler manual is not mentioning anything about the storage.

well mostly you don't care. You might want to try a compiler
specific ng. It's even possible the internal details of the
compiler arn't publicly documented.


What do u think can be the best possible solution for static variable
storage?

there probably is no "best" solution. The memory must
be accessible by the function and have a lifetime the same
as the program. It is initialised before it is accessed for t
he first time. It is common for all statics (local and global)
to be in the same lump of memory.

Why do you need to know?


--
Nick Keighley

.



Relevant Pages

  • Re: multiple return values
    ... isn't a first class object. ... which could be on the stack. ... they are managed by the compiler. ... Keeping the memory locations and the entire mechanism shrouded from the ...
    (comp.lang.lisp)
  • Re: Why not auto?
    ... >>> on a system where stack space is limited declaring all local variables ... The compiler is in a perfect position to know which parameters would ... The compiler could also apply such optimisations to automatic ... likely to promote memory reuse and improved caching. ...
    (comp.lang.c)
  • Re: next mystery: 32 vs 64 bits...
    ... etc. Stack and register reorganization are always ... (this is not too much of a problem in my compiler, I just resort back to the ... given the newer way I am handling memory references (better ... 'on stack' typically, is not 'in memory'. ...
    (alt.lang.asm)
  • Re: Doubts in shellcode !?
    ... The compiler actually generates a "call" instruction ... transfer by manipulating the data on the stack, ... > |> and clobber memory that you have no business clobbering.... ... just to make sure no local pointers got out of control and ...
    (comp.security.unix)
  • Re: Some stack questions
    ... The stack has storage allocated for it before main ... On some platforms, virtual memory is ... Information needed to restore the calling function's context is part of what is saved on the stack, and the function arguments are also stored on the stack; further, space is reserved on the stack for all variables having "auto" storage class for that specific invocation of the function. ... the compiler allocates registers efficiently so that most operations are done without using temp storage. ...
    (comp.lang.c.moderated)