Expert C Programming

(Jeff_L) #1

The BSS segment gets its name from abbreviating "Block Started by Symbol"—a pseudo-op from the
old IBM 704 assembler, carried over into UNIX, and there ever since. Some people like to remember
it as "Better Save Space." Since the BSS segment only holds variables that don't have any value yet, it
doesn't actually need to store the image of these variables. The size that BSS will require at runtime is
recorded in the object file, but BSS (unlike the data segment) doesn't take up any actual space in the
object file.


Programming Challenge


Look at the Segments in an Executable


1. Compile the "hello world" program, run ls -lon the executable to get its overall


size, and run size to get the sizes of the segments within it.



  1. Add the declaration of a global array of 1000 ints, recompile, and repeat the
    measurements. Notice the differences.

  2. Now add an initial value in the declaration of the array (remember, C doesn't force
    you to provide a value for every element of an array in an initializer). This will
    move the array from the BSS segment to the data segment. Repeat the
    measurements. Notice the differences.

  3. Now add the declaration of a big array local to a function. Declare a second big
    local array with an initializer. Repeat the measurements. Is data defined locally
    inside a function stored in the executable? Does it make any difference if it's
    initialized or not?

  4. What changes occur to file and segment sizes if you compile for debugging? For
    maximum optimization?

Free download pdf