Keil Logo

C51: Global or Static Variables Not Being Initialized


Information in this article applies to:

  • C51

SYMPTOMS

I have some static and global variables which I am initializing when I declare them. When I run my program the variables are not initialized.

On stepping through the startup code it appears that the first byte of ?C_INITSEG - where all the initial values are stored - is set to 00H and this causes the initialization code to terminate prematurely.

CAUSE

The module INIT.A51 contains the initialization table terminator (=0). If this module is explicitly linked to an application, it must be the last module included in the linkage so that the terminator is located at the end of the initialization table. Usually, the linker takes the INIT module out of the libraries and automatically locates it at the right position.

Some customers have reported this problem when using Microsoft Make. By converting their project to use µVision the problem was resolved. It appears that in the process of converting the project, the INIT.A51 file was excluded (and was automatically included from the library) or was placed at the end of the file list.

RESOLUTION

Include the module INIT.A51 in your project only if you have modified it. If you need it, drag it to the very bottom of the µVision project window. If you use a linker command file, specify the INIT.OBJ file as the last module.

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


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.