2010年12月21日 星期二

bss section

The computer program memory is organized into the following:

    * Data Segment (Data + BSS + Heap)
    * Stack
    * Code segment
Typically, the program loader initializes the memory allocated
for the bss section when it loads the program. Operating systems
may use a technique called zero-fill-on-demand to efficiently
implement the bss segment (McKusick & Karels 1986).
In embedded software, the bss segment is mapped into memory that
is initialized to zero by the C run-time system before main()
is entered.
 
#include <stdio.h>

extern int __bss_start, _end;

int a, b, c, d;  /* un-initialized */

int main()
{
        int *ptr;
        a = 1, b = 2, c = 3, d = 4;

        for (ptr = &__bss_start; ptr != &_end; ptr++) {
                printf("%d\n", *ptr);
        }
        return 0;
}

沒有留言:

張貼留言