| |||||
Technical Support Support Resources
Product Information | GCC: VARIABLES DO NOT GET INITIALIZED WITH GNU CInformation in this article applies to:
QUESTIONI have a variable initialization in my C program:
int ival=0x34;
void main (void) {
:
:
}
When the execution reaches 'main', the variable is not initialized. What is the problem? ANSWERThere is a potential problem in the STARTUP.S file. The code section Clear .bss section (Zero init) should be before Relocate .data section (Copy from ROM to RAM). Make sure that your STARTUP.S code looks like this:
:
:
# Clear .bss section (Zero init)
MOV R0, #0
LDR R1, =__bss_start__
LDR R2, =__bss_end__
LoopZI: CMP R1, R2
STRLO R0, [R1], #4
BLO LoopZI
# Relocate .data section (Copy from ROM to RAM)
LDR R1, =_etext
LDR R2, =_data
LDR R3, =_edata
LoopRel: CMP R2, R3
LDRLO R0, [R1], #4
STRLO R0, [R2], #4
BLO LoopRel
:
:
MORE INFORMATION
SEE ALSO
Last Reviewed: Monday, July 10, 2006 | ||||