0

As per my understanding, initialized data section contains static and global variable that are explicitly initialized. .bss section contains uninitialized global and static variable.

Why we need 2 different section i.e initialized data section and .bss section? What is advantage of such structure?

Where string literal gets store(in which section)? e.g. char * ptr = "ABCD";

HemF
  • 19
  • 3
  • 2
    The advantage is that the `.data` section is consuming the binary file size as it has to have all of the initializers in it. The zero-initialized section is not written in the binary, because everything there is just zero. – Eugene Sh. Feb 09 '18 at 20:15
  • In C, there is no such thing as an unitialised variable with static storage duration. A static-lifetime variable without an explicit initialiser is initialised to 0 (or equivalent thereof). – rici Feb 09 '18 at 20:30
  • Here uninitialized static variable refered to variable which are not initialized explicitly by programmer and they initialized to 0. e.g. static into x; here x is initialized to 0 and goes to in .bas section. Now, static int y = 10. This variable go to initialized data section as it is explicitly initialized in program. My question is why 2 different sections are created? What is advantage? – HemF Feb 11 '18 at 05:30
  • For example, static int x; now x is stored in .bas section as it is not explicitly initialized. Now suppose I have another variable static in y =10; This y will store in initialized data section. Why we need to maintain 2 different sections? I am beginner to ELF format.Please explain with example with respect to ELF format. – HemF Feb 11 '18 at 05:42

0 Answers0