23Fermer25
christopLe 20/04/2010 à 21:35
Lionel Debroux (./19) :
Are static variables (both local to a function and local to a source file (or "compilation unit")) also stored in the BSS section? From what I understand about C, they should be.

If they're not explicitly initialized, they will be in the BSS section.
If they're explicitly initialized and not const, they will be in the .data section (-> RAM).If they're explicitly initialized and const, they will be in the .rodata section (-> Flash).

PpHd (./22) :

Provided that they are not initialised to a value, yes.

The only problem is that if you write:
int x = 2;
as a global, x will be mapped to the ROM code, making it impossible to change.


Which is it? Are initialized global variables put in the .data section, and is the .data section in RAM or FlashROM?

If an initialized global variable is in RAM, where is its initialized value stored? Would I have to write startup code to copy the initial values from FlashROM to the appropriate locations in RAM?

On the other hand, if the .data section is stored in FlashROM, are there plans to add an option to the linker to put it in RAM, like with BSS?