IT lexicon › Programming › Data segment

Data segment

Programming På svenska → Updated: 2026-11-04

The .data section, holding global and static variables with a non-zero initial value. In firmware, that means they have to exist in two places at once.

Write int baud = 115200; outside a function and the variable lands in .data. On a desktop, the OS loads that section from the executable. A microcontroller has no OS, and RAM is blank after reset. So the initial value is stored in flash while the variable itself lives in RAM.

The linker script gives the section two addresses: the LMA, where the bytes sit in flash, and the VMA, where the code expects to find them. Startup code copies one to the other before calling main(). Leave the copy out and everything compiles cleanly, but every initialised global holds garbage. The first time, it's an afternoon's debugging. Every time after that, ten seconds.

← Back to the lexicon