5.10.2.1 Initialization Of Objects
One task of the runtime startup code is to ensure that any static storage duration objects contain their initial value before the program begins execution. A case in point would be input in the following example.
int input = 88;
In the code above, the initial value (0x88
) will be
stored as data in program memory and will be copied to the memory reserved for
input
by the runtime startup code. For efficiency, initial values are
stored as blocks of data and copied by loops.
Absolute variables are never initialized and must be explicitly assigned a value if that is required for correct program execution.
The initialization of objects can be disabled using
-Wl,--no-data-init
; however, code that relies on objects containing
their initial value will fail.
EBTRx
bits on
some PIC18 devices. If this protection feature is enabled and the initial values for data
objects fall within the protected blocks of program memory, the runtime startup code might
fail to properly initialize those objects. Ensure that the sections holding initial values
are not linked into protected program memory blocks.Since auto
objects are dynamically created, they require
code to be positioned in the function in which they are defined to perform their
initialization and are not considered by the runtime startup code.
auto
variables can impact on
code performance, particularly if the objects are large in size. Consider using
static
local objects instead.Objects whose content
should be preserved over a Reset should be marked with the __persistent
qualifier. Such objects are linked in a different area of memory and are not altered by the
runtime startup code.
The runtime startup code that initializes objects will clobber the content of the STATUS register. If you need to determine the cause of reset from this register, the register content can be preserved.