On Wed, 01 Aug 2007 01:15:45 -0000, linq936 <li*****@hotmail.com>
wrote in comp.lang.c:
Hi,
I hope this question belongs to this group.
Actually, it really does not.
I am studying book <<Expert C Programming>and in the chapter of
run time data structure, it mentions that BSS segment only stores the
size of the un-initialized data, it does not have the data images, so
it does not take up any actual space in the object file.
Assuming that you are talking about the book "Expert C Programming:
Deep C Secrets" by Peter van der Linden, it is indeed an excellent
book for intermediate to advanced C programmers.
One thing that you need to understand is that this book was written in
1994, 13 years ago, and things can change in that time. The C
language does not actually specify things like segments, a BSS
segment, Or ELF, COFF, a.out, OMF86, or any other file format. Peter
was talking about the behavior typical UNIX implementations that he
was familiar with at the time, not anything specified by C or UNIX or
guaranteed to remain unchanged forever.
I tried out a simple code, but it is not as said.
Here is my first code:
#include <stdio.h>
int main(void){
printf("hello");
}
and I run size command:
size a.out
text data bss dec hex filename
874 256 4 1134 46e a.out
You see bss is of size 4.
Now the 2nd code:
#include <stdio.h>
int arr[1000];
int main(void){
printf("hello");
}
and size command output:
size a.out
text data bss dec hex filename
874 256 4032 5162 142a a.out
so bss size increases roughly the array size!
Is this because my GCC on Intel machine has different format than
before?
Also, it is quite possible that what Peter said applies to your
compiler, but you are misunderstanding what he wrote. Since the
executable file must store the size, if not the contents, of the BSS
segment, what would you expect the "size" command to report?
What you really want to know is the difference in the file size of the
two a.out files themselves. If the second file is about 4,000 octets
larger than the first, the compiler and linker are storing 1,000 int
values of 0 in the file. If the second file is about the same size as
the first, perhaps just slightly larger, then it is obviously not
storing all those 0 valued ints in the file.
If you have further questions about object files, executable files,
segments, or other such thing are specific to your tool set, and not
defined by the language, you should ask in places like a gcc support
group (gnu.gcc.*), or perhaps news:comp.os.linux-development.apps or
news:comp.unix.programmer, if you develop on one of those platforms.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html