if a global or static C variable is not explicitly initialized, but implicitly initialized, is it in .data or .bss section?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Computer Systems: A Programmer's Perspective says about two sections in a ELF relocatable object file:
.data Initialized global and static C variables. Local C variables are maintained at run time on the stack and do not appear in
either the .data or .bss sections.
.bss Uninitialized global and static C variables, along with any global or static variables that are initialized to zero. This section
occupies no actual space in the object ï¬Âle; it is merely a
placeholder. Object ï¬Âle formats distinguish between initialized and
uninitialized variables for space efï¬Âciency: unini- tialized variables
do not have to occupy any actual disk space in the object ï¬Âle. At run
time, these variables are allocated in memory with an initial value of
zero.
Do "initialized" and "unitiailized" in the quote mean explicitly or implicitly or either?
if a global or static C variable is not explicitly initialized, but implicitly initialized, is it in .data or .bss section?
Does it matter whether the global or static C variable is implicitly initialized to zero or nonzero?
The requirements for .data and for .bss are not mutually exclusive.
The .data requirement of "Initialized global and static C variables" doesn't say that such variables must be initialized to nonzero. So if a global or static C variable is initialized to zero, should it be in .data or .bss section?
Thanks.
elf
add a comment |Â
up vote
1
down vote
favorite
Computer Systems: A Programmer's Perspective says about two sections in a ELF relocatable object file:
.data Initialized global and static C variables. Local C variables are maintained at run time on the stack and do not appear in
either the .data or .bss sections.
.bss Uninitialized global and static C variables, along with any global or static variables that are initialized to zero. This section
occupies no actual space in the object ï¬Âle; it is merely a
placeholder. Object ï¬Âle formats distinguish between initialized and
uninitialized variables for space efï¬Âciency: unini- tialized variables
do not have to occupy any actual disk space in the object ï¬Âle. At run
time, these variables are allocated in memory with an initial value of
zero.
Do "initialized" and "unitiailized" in the quote mean explicitly or implicitly or either?
if a global or static C variable is not explicitly initialized, but implicitly initialized, is it in .data or .bss section?
Does it matter whether the global or static C variable is implicitly initialized to zero or nonzero?
The requirements for .data and for .bss are not mutually exclusive.
The .data requirement of "Initialized global and static C variables" doesn't say that such variables must be initialized to nonzero. So if a global or static C variable is initialized to zero, should it be in .data or .bss section?
Thanks.
elf
Why don't you write a small C program, and test what happens?
â dirkt
4 hours ago
1
It doesn't matter if it's "implicitly" or "explicitly" initialized -- If it starts out as 0, it's in thebss
.
â mosvy
4 hours ago
@mosvy .data is only for Initialized global and static C variables initialized to nonzero?
â Tim
4 hours ago
that's the way it is by default. but you can force a variable into the.data
section with eg.int var __attribute((section (".data")));
.
â mosvy
1 hour ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Computer Systems: A Programmer's Perspective says about two sections in a ELF relocatable object file:
.data Initialized global and static C variables. Local C variables are maintained at run time on the stack and do not appear in
either the .data or .bss sections.
.bss Uninitialized global and static C variables, along with any global or static variables that are initialized to zero. This section
occupies no actual space in the object ï¬Âle; it is merely a
placeholder. Object ï¬Âle formats distinguish between initialized and
uninitialized variables for space efï¬Âciency: unini- tialized variables
do not have to occupy any actual disk space in the object ï¬Âle. At run
time, these variables are allocated in memory with an initial value of
zero.
Do "initialized" and "unitiailized" in the quote mean explicitly or implicitly or either?
if a global or static C variable is not explicitly initialized, but implicitly initialized, is it in .data or .bss section?
Does it matter whether the global or static C variable is implicitly initialized to zero or nonzero?
The requirements for .data and for .bss are not mutually exclusive.
The .data requirement of "Initialized global and static C variables" doesn't say that such variables must be initialized to nonzero. So if a global or static C variable is initialized to zero, should it be in .data or .bss section?
Thanks.
elf
Computer Systems: A Programmer's Perspective says about two sections in a ELF relocatable object file:
.data Initialized global and static C variables. Local C variables are maintained at run time on the stack and do not appear in
either the .data or .bss sections.
.bss Uninitialized global and static C variables, along with any global or static variables that are initialized to zero. This section
occupies no actual space in the object ï¬Âle; it is merely a
placeholder. Object ï¬Âle formats distinguish between initialized and
uninitialized variables for space efï¬Âciency: unini- tialized variables
do not have to occupy any actual disk space in the object ï¬Âle. At run
time, these variables are allocated in memory with an initial value of
zero.
Do "initialized" and "unitiailized" in the quote mean explicitly or implicitly or either?
if a global or static C variable is not explicitly initialized, but implicitly initialized, is it in .data or .bss section?
Does it matter whether the global or static C variable is implicitly initialized to zero or nonzero?
The requirements for .data and for .bss are not mutually exclusive.
The .data requirement of "Initialized global and static C variables" doesn't say that such variables must be initialized to nonzero. So if a global or static C variable is initialized to zero, should it be in .data or .bss section?
Thanks.
elf
elf
edited 4 hours ago
asked 4 hours ago
Tim
24.2k69233424
24.2k69233424
Why don't you write a small C program, and test what happens?
â dirkt
4 hours ago
1
It doesn't matter if it's "implicitly" or "explicitly" initialized -- If it starts out as 0, it's in thebss
.
â mosvy
4 hours ago
@mosvy .data is only for Initialized global and static C variables initialized to nonzero?
â Tim
4 hours ago
that's the way it is by default. but you can force a variable into the.data
section with eg.int var __attribute((section (".data")));
.
â mosvy
1 hour ago
add a comment |Â
Why don't you write a small C program, and test what happens?
â dirkt
4 hours ago
1
It doesn't matter if it's "implicitly" or "explicitly" initialized -- If it starts out as 0, it's in thebss
.
â mosvy
4 hours ago
@mosvy .data is only for Initialized global and static C variables initialized to nonzero?
â Tim
4 hours ago
that's the way it is by default. but you can force a variable into the.data
section with eg.int var __attribute((section (".data")));
.
â mosvy
1 hour ago
Why don't you write a small C program, and test what happens?
â dirkt
4 hours ago
Why don't you write a small C program, and test what happens?
â dirkt
4 hours ago
1
1
It doesn't matter if it's "implicitly" or "explicitly" initialized -- If it starts out as 0, it's in the
bss
.â mosvy
4 hours ago
It doesn't matter if it's "implicitly" or "explicitly" initialized -- If it starts out as 0, it's in the
bss
.â mosvy
4 hours ago
@mosvy .data is only for Initialized global and static C variables initialized to nonzero?
â Tim
4 hours ago
@mosvy .data is only for Initialized global and static C variables initialized to nonzero?
â Tim
4 hours ago
that's the way it is by default. but you can force a variable into the
.data
section with eg. int var __attribute((section (".data")));
.â mosvy
1 hour ago
that's the way it is by default. but you can force a variable into the
.data
section with eg. int var __attribute((section (".data")));
.â mosvy
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
Do "initialized" and "unitiailized" in the quote mean explicitly or implicitly or either?
âÂÂInitialisedâ means that the variable is given an explicit value (which might be zero) alongside its declaration in the code. âÂÂUninitialisedâ means that the variable isnâÂÂt explicitly initialised at declaration time, which in your terminology corresponds to âÂÂimplicitly initialisedâÂÂ; if itâÂÂs a global variable, its value is zero.
If a global or static C variable is not explicitly initialized, but implicitly initialized, is it in .data or .bss section?
As per your quote:
.bss Uninitialized global and static C variables
Next:
Does it matter whether the global or static C variable is implicitly initialized to zero or nonzero?
Uninitialised global variables are zero-valued by default.
So if a global or static C variable is initialized to zero, should it be in .data or .bss section?
As per your quote:
.bss Uninitialized global and static C variables, along with any global or static variables that are initialized to zero.
Note that none of this is a requirement; in particular, it assumes that uninitialised data segments are initialised to values corresponding to zero in C on the platform. This is typically the case on systems using ELF, but C allows zero to be represented by a bit pattern other than all zeroes.
In practice however, global or static variables initialised to zero, explicitly or not, are part of .bss
in ELF binaries.
Thanks. Is .data only for Initialized global and static C variables initialized to nonzero?
â Tim
3 hours ago
Yes, your quote itself says âÂÂany global or static variables that are initialized to zeroâ go in.bss
, not.data
. See the Wikipedia page on.bss
for more background.
â Stephen Kitt
3 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Do "initialized" and "unitiailized" in the quote mean explicitly or implicitly or either?
âÂÂInitialisedâ means that the variable is given an explicit value (which might be zero) alongside its declaration in the code. âÂÂUninitialisedâ means that the variable isnâÂÂt explicitly initialised at declaration time, which in your terminology corresponds to âÂÂimplicitly initialisedâÂÂ; if itâÂÂs a global variable, its value is zero.
If a global or static C variable is not explicitly initialized, but implicitly initialized, is it in .data or .bss section?
As per your quote:
.bss Uninitialized global and static C variables
Next:
Does it matter whether the global or static C variable is implicitly initialized to zero or nonzero?
Uninitialised global variables are zero-valued by default.
So if a global or static C variable is initialized to zero, should it be in .data or .bss section?
As per your quote:
.bss Uninitialized global and static C variables, along with any global or static variables that are initialized to zero.
Note that none of this is a requirement; in particular, it assumes that uninitialised data segments are initialised to values corresponding to zero in C on the platform. This is typically the case on systems using ELF, but C allows zero to be represented by a bit pattern other than all zeroes.
In practice however, global or static variables initialised to zero, explicitly or not, are part of .bss
in ELF binaries.
Thanks. Is .data only for Initialized global and static C variables initialized to nonzero?
â Tim
3 hours ago
Yes, your quote itself says âÂÂany global or static variables that are initialized to zeroâ go in.bss
, not.data
. See the Wikipedia page on.bss
for more background.
â Stephen Kitt
3 hours ago
add a comment |Â
up vote
2
down vote
Do "initialized" and "unitiailized" in the quote mean explicitly or implicitly or either?
âÂÂInitialisedâ means that the variable is given an explicit value (which might be zero) alongside its declaration in the code. âÂÂUninitialisedâ means that the variable isnâÂÂt explicitly initialised at declaration time, which in your terminology corresponds to âÂÂimplicitly initialisedâÂÂ; if itâÂÂs a global variable, its value is zero.
If a global or static C variable is not explicitly initialized, but implicitly initialized, is it in .data or .bss section?
As per your quote:
.bss Uninitialized global and static C variables
Next:
Does it matter whether the global or static C variable is implicitly initialized to zero or nonzero?
Uninitialised global variables are zero-valued by default.
So if a global or static C variable is initialized to zero, should it be in .data or .bss section?
As per your quote:
.bss Uninitialized global and static C variables, along with any global or static variables that are initialized to zero.
Note that none of this is a requirement; in particular, it assumes that uninitialised data segments are initialised to values corresponding to zero in C on the platform. This is typically the case on systems using ELF, but C allows zero to be represented by a bit pattern other than all zeroes.
In practice however, global or static variables initialised to zero, explicitly or not, are part of .bss
in ELF binaries.
Thanks. Is .data only for Initialized global and static C variables initialized to nonzero?
â Tim
3 hours ago
Yes, your quote itself says âÂÂany global or static variables that are initialized to zeroâ go in.bss
, not.data
. See the Wikipedia page on.bss
for more background.
â Stephen Kitt
3 hours ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Do "initialized" and "unitiailized" in the quote mean explicitly or implicitly or either?
âÂÂInitialisedâ means that the variable is given an explicit value (which might be zero) alongside its declaration in the code. âÂÂUninitialisedâ means that the variable isnâÂÂt explicitly initialised at declaration time, which in your terminology corresponds to âÂÂimplicitly initialisedâÂÂ; if itâÂÂs a global variable, its value is zero.
If a global or static C variable is not explicitly initialized, but implicitly initialized, is it in .data or .bss section?
As per your quote:
.bss Uninitialized global and static C variables
Next:
Does it matter whether the global or static C variable is implicitly initialized to zero or nonzero?
Uninitialised global variables are zero-valued by default.
So if a global or static C variable is initialized to zero, should it be in .data or .bss section?
As per your quote:
.bss Uninitialized global and static C variables, along with any global or static variables that are initialized to zero.
Note that none of this is a requirement; in particular, it assumes that uninitialised data segments are initialised to values corresponding to zero in C on the platform. This is typically the case on systems using ELF, but C allows zero to be represented by a bit pattern other than all zeroes.
In practice however, global or static variables initialised to zero, explicitly or not, are part of .bss
in ELF binaries.
Do "initialized" and "unitiailized" in the quote mean explicitly or implicitly or either?
âÂÂInitialisedâ means that the variable is given an explicit value (which might be zero) alongside its declaration in the code. âÂÂUninitialisedâ means that the variable isnâÂÂt explicitly initialised at declaration time, which in your terminology corresponds to âÂÂimplicitly initialisedâÂÂ; if itâÂÂs a global variable, its value is zero.
If a global or static C variable is not explicitly initialized, but implicitly initialized, is it in .data or .bss section?
As per your quote:
.bss Uninitialized global and static C variables
Next:
Does it matter whether the global or static C variable is implicitly initialized to zero or nonzero?
Uninitialised global variables are zero-valued by default.
So if a global or static C variable is initialized to zero, should it be in .data or .bss section?
As per your quote:
.bss Uninitialized global and static C variables, along with any global or static variables that are initialized to zero.
Note that none of this is a requirement; in particular, it assumes that uninitialised data segments are initialised to values corresponding to zero in C on the platform. This is typically the case on systems using ELF, but C allows zero to be represented by a bit pattern other than all zeroes.
In practice however, global or static variables initialised to zero, explicitly or not, are part of .bss
in ELF binaries.
edited 3 hours ago
answered 3 hours ago
Stephen Kitt
152k23337405
152k23337405
Thanks. Is .data only for Initialized global and static C variables initialized to nonzero?
â Tim
3 hours ago
Yes, your quote itself says âÂÂany global or static variables that are initialized to zeroâ go in.bss
, not.data
. See the Wikipedia page on.bss
for more background.
â Stephen Kitt
3 hours ago
add a comment |Â
Thanks. Is .data only for Initialized global and static C variables initialized to nonzero?
â Tim
3 hours ago
Yes, your quote itself says âÂÂany global or static variables that are initialized to zeroâ go in.bss
, not.data
. See the Wikipedia page on.bss
for more background.
â Stephen Kitt
3 hours ago
Thanks. Is .data only for Initialized global and static C variables initialized to nonzero?
â Tim
3 hours ago
Thanks. Is .data only for Initialized global and static C variables initialized to nonzero?
â Tim
3 hours ago
Yes, your quote itself says âÂÂany global or static variables that are initialized to zeroâ go in
.bss
, not .data
. See the Wikipedia page on .bss
for more background.â Stephen Kitt
3 hours ago
Yes, your quote itself says âÂÂany global or static variables that are initialized to zeroâ go in
.bss
, not .data
. See the Wikipedia page on .bss
for more background.â Stephen Kitt
3 hours ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476895%2fif-a-global-or-static-c-variable-is-not-explicitly-initialized-but-implicitly-i%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Why don't you write a small C program, and test what happens?
â dirkt
4 hours ago
1
It doesn't matter if it's "implicitly" or "explicitly" initialized -- If it starts out as 0, it's in the
bss
.â mosvy
4 hours ago
@mosvy .data is only for Initialized global and static C variables initialized to nonzero?
â Tim
4 hours ago
that's the way it is by default. but you can force a variable into the
.data
section with eg.int var __attribute((section (".data")));
.â mosvy
1 hour ago