Keil Logo

C51: WHEN/WHERE ARE GLOBAL AND STATIC VARIABLES INITIALIZED?


Information in this article applies to:

  • C51 Version 5.50

QUESTION

How does the compiler handle variables that are initialized when declared? If I write something like the following in a function:

static int temp = 1;

or initialize a global variable, how will the variable be initialized? I do not see anything in the STARTUP.A51 file to move initialized data from ROM to RAM.

ANSWER

The initial values of global and static variables are stored in ROM in a segment called ?C_INITSEG. They are then copied to the relevent RAM locations after the code in STARTUP.A51 has been executed and before the main() function is called. The code that performs the variable initialization may be found in the file INIT.A51 inside the LIB folder.

We strongly recommend that you do not modify the INIT.A51 file.

MORE INFORMATION

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Friday, July 15, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.