Global variable not assigned a value in initialization code
Global variable is not assigned a value in the initialization section of program
Description
This check determines if all non-const global variables (and local static variables) are explicitly assigned a value at declaration or in the section of code designated as initialization code.
To indicate the end of initialization code, you enter the line
#pragma polyspace_end_of_init
main
function. The initialization code starts from the beginning of
main
and continues up to this pragma. To enable this check, use the
option Check that global variables are initialized after warm reboot
(-check-globals-init)
.The check on a global variable is:
Red, if the variable is not initialized at all, either explicitly at declaration or in the initialization code (or is initialized in dead code within the initialization code).
Orange, if the variable is not initialized on certain execution paths through the initialization code. For instance, the variable is initialized in an
if
branch of a conditional statement but not theelse
branch.Green, if the variable is always initialized once the initialization code completes execution.
In a warm reboot, to save time, the data segment of a program, which might hold variable values from a previous state, is not loaded. Instead, the program is supposed to explicitly initialize all non-const variables before execution. This check verifies that all non-const global variables are indeed initialized in a warm reboot.
Diagnosing This Check
Browse through all instances of the uninitialized or possibly uninitialized variable on
the Variable Access pane (or the Global Variables
pane in the Polyspace® Access web interface). See if any of the references occur before the pragma
polyspace_end_of_init
is encountered.
See also Variable Access in Polyspace Desktop User Interface.
Examples
Check Information
Group: Data flow |
Language: C |
Acronym: GLOBAL_SET_AT_INITIALIZATION |