Keil™, An ARM® Company

Technical Support

GCC: VARIABLES DO NOT GET INITIALIZED WITH GNU C


Information in this article applies to:

  • GNU C Compiler for ARM Version 3.22

QUESTION

I 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?

ANSWER

There 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

  • Getting Started User's Guide (GSA.CHM), CPU Setup

SEE ALSO

Last Reviewed: Monday, July 10, 2006


Did this article provide the answer you needed?