Static Variables

M

Murali

Hi

Can anyone tell me where a static variable be stored. I am sure that it is
stored in the data segment of the executable's memory footprint...But in
what? a stack or a heap or is it purely compiler/OS dependent?

Thanks in advance...

Murali
 
E

Eric Sosman

Murali said:
Hi

Can anyone tell me where a static variable be stored. I am sure that it is
stored in the data segment of the executable's memory footprint...But in
what? a stack or a heap or is it purely compiler/OS dependent?

A static variable is stored "somewhere." The "somewhere"
is allocated and initialized ("somehow") before the program's
C code starts to execute, and remains allocated until the
program terminates.

All the details are implementation-dependent, and are in
fact different on different implementations.
 
D

Dan Pop

In said:
Can anyone tell me where a static variable be stored. I am sure that it is
stored in the data segment of the executable's memory footprint...But in
what? a stack or a heap or is it purely compiler/OS dependent?

Stack and heap are dynamical data structures, while a static variable is
allocated for the entire duration of program's execution, so neither stack
nor heap are convenient for it. So, it's stored in that region of the
data segment that is allocated at program startup and deallocated at
program termination, along with all other statically allocated variables
of the program.

Dan
 
R

Ravi Uday

Stack and heap are dynamical data structures, while a static variable is
allocated for the entire duration of program's execution, so neither stack
nor heap are convenient for it. So, it's stored in that region of the
data segment that is allocated at program startup and deallocated at
program termination, along with all other statically allocated variables
of the program.

Is it not that static variables are allocated in Data segment if there are
initialized, else in bss if they are un-initialized.
 
R

Ravi Uday

Stack and heap are dynamical data structures, while a static variable is
allocated for the entire duration of program's execution, so neither stack
nor heap are convenient for it. So, it's stored in that region of the
data segment that is allocated at program startup and deallocated at
program termination, along with all other statically allocated variables
of the program.

Is it not that static variables are allocated in Data segment if there are
initialized, else in bss if they are un-initialized.
 
M

Martin Ambuhl

Ravi said:
Is it not that static variables are allocated in Data segment if there are
initialized, else in bss if they are un-initialized.

No. Neither of "Data segment" or "bss" have any meaning for C. They
may have meaning in the parochial world your machine and OS represent.
 
R

Ravi Uday

Stack and heap are dynamical data structures, while a static variable is
allocated for the entire duration of program's execution, so neither stack
nor heap are convenient for it. So, it's stored in that region of the
data segment that is allocated at program startup and deallocated at
program termination, along with all other statically allocated variables
of the program.

Dan

Is it not that static variables are allocated in Data segment if they are
initialized, else in bss if they are un-initialized.
 
M

Martin Ambuhl

Ravi said:
Is it not that static variables are allocated in Data segment if they are
initialized, else in bss if they are un-initialized.

Is it not time for you to stop posting this over and over? No. You are
wrong. See my reply 30 minutes _before_ your third reposting.
 
D

Dan Pop

In said:
Is it not that static variables are allocated in Data segment if there are
initialized, else in bss if they are un-initialized.

Static variables are *always* initialised and bss is typically part of the
data segment.

Dan
 
R

Ravi Uday

Martin Ambuhl said:
Is it not time for you to stop posting this over and over? No. You are
wrong. See my reply 30 minutes _before_ your third reposting.

Martin,
Sorry i did not mean to post it over and over!! Just that my browser
did not refresh and gave 'page not found..etc..' so i reposted that
again.

<OT>
But in Dans reply he says bss is a part of data segment !! Is it ?
Where can
i see some notes on these.

- Ravi
<OT>
 
M

Martin Ambuhl

Ravi Uday wrote:

But in Dans reply he says bss is a part of data segment !! Is it ?

Dan, for reasons known only to him, decided to answer an off-topic
question with an off-topic answer.
Where can
i see some notes on these.

In documentation for your implementation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top