Keil Logo

C51: Variable Zero Initialization


Information in this article applies to:

  • C51, all versions
  • CX51, all versions
  • C251, all versions

QUESTION

The C51 User's Guide states that the file INIT.A51 initializes variables that were explicitly initialized in the 'C' source.

Does it also initialize variables that are implicitly initialized to zero, or does it rely on the zeroing of memory in STARTUP.A51 to do this?

Is there a difference in the following two statements, or are they identical?

static int xdata xi;

static int xdata xi = 0;

ANSWER

Yes, the compiler relies on the zero initialization in the STARTUP file. For strict ANSI compliance, it is important that the settings match with your hardware.

When you make explicit assignments such as:

static int xdata xi = 0;

the variables get set to zero by the INIT.A51 file. This behavior allows you to use non-volatile memory for variables.

MORE INFORMATION

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.