Program Memory
The program memory is split in the following sections:
- Code Segment (.text)
This section (read-only and fixed size) contains the executable instructions.
int foo(int bar) {
printf("bar=%d\n", bar);
}
- Data Segment (.data)
The data segment contains global or static variables with an pre-defined value. It includes also static variables, declared inside a function. This segment is write-able.
int foo = 12;
static char bar[] = "hugo";
- Block Started by Symbol Segment (.bss)
The BSS segment - also known as the uninitialized data - contains all (global, or static inside a function) variables which are uninitialized or initialized to zero (Unix, Windows). Unix-like operating systems and Windows initialize the BSS segment with zero (allowing to place zero initialized variables in this segment) - other operating systems may handle it differently. Typically only the length of this section is stored in the object file, not the content. This segment is write-able.
int foo = 0;
static char bar[128];
- Read-only Data Segment (.rodata)
The RODATA segment contains constants (const modifier) and strings. As it's name says, this segment is read-only.
const int foo = 0;
const char* bar = "foobar";
As a consequence, on Unix-like OSs or Windows only local variables (inside function) can be uninitialized.
Source: