Re: Where is a static variable stored?




Jack wrote:
Michael Mair wrote:
Jack schrieb:
Thanks.

You're welcome.

Please write/repeat your question in the message text -- there
are newsreaders which do not show subject and message text at
the same time.

Your question: "Where is a static variable stored?" has no
standard C answer.
Variables with static storage duration "live" throughout the
programme's lifetime. Whether they are stored all or only part
of the time in RAM, ROM, or registers is not specified -- they
have only to behave as if they were there the whole time.

This may not be the answer to what you _wanted_ to ask; please
be precise in your questions.

I think for a static variable defined out of any functions, i.e., it is
a global variable, it is located in the data segment of the program.
How about a static variable defined within a function? it is a local
variable. Is it located at the stack?

You were given several complete and correct answers to this 5 days ago.
What about the answers do you not understand? The C language does not
define where the data is stored. It can't, because it has to work on
many different types of computers. You can run code written in C on
machines that don't have data segments and don't have stacks - so how
could a variable be stored in either the data segment or the stack in
this case?

Why do you care where it's stored? People need to know this to be able
to tell you what you really want to know.

If you're looking for answers about a particular Operating System
running on a particular type of computer, you need to ask in a group
which discusses that OS on that computer.

.



Relevant Pages

  • Re: [PATCH RFC/RFB] x86_64, i386: interrupt dispatch changes
    ... | that instruction sequence. ... the cost is 6 cycles instead of 1 cycles. ... save the current data segment registers (the stack segment and code ... I kept the information that is saved on the stack exactly the ...
    (Linux-Kernel)
  • Re: whether this is valid
    ... located in data segment which is read only. ... And your *a is a pointer (located in your stack that means it be able ... This variable pointed to address that "str" located. ... you in stack and copy "str" from data segment to that memory. ...
    (comp.lang.c)
  • Re: Static Variables
    ... Stack and heap are dynamical data structures, ... data segment that is allocated at program startup and deallocated at ... Dan Pop ...
    (comp.lang.c)
  • Re: where the storage will be allocated
    ... static ushort fractionalValue={ ... "fractionalValue" would be allocated (stack or data segment)? ... Or the compiler generate a code, that would allocate space on the ...
    (comp.lang.c)