The size of the BSS partition is software dependent. It describes the amount of data that is initialized to "all bytes zero". Zero values ββare not actually stored in the object file, but the size of the BSS section is preserved.
The data section contains the initial values ββof all data structures that are not initialized with "all bytes of zero"; It also changes between programs. It does not include the space included in the BSS section.
You will get a larger BSS section with this program:
#include <stdio.h>
The code shuffles numbers from 0 to 99 with some bias in generating random numbers (so this is not an ideal shuffle, but it really is not an exercise point - it is just non-trivial code that uses a static array, although a local variable will suffice). When I run size (on Ubuntu 13.10), I get:
text data bss dec hex filename 1593 584 432 2609 a31 shuffle
For comparison, in the "hello" program in the question, I get:
text data bss dec hex filename 1200 560 8 1768 6e8 hello
The main difference is that array a occupies 400 bytes; the remaining 24 bytes of BSS belong to a different code.
source share