4.9.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.
The initialization of objects can be disabled using
-Wl,--no-data-init
; however, code that relies on objects containing
their initial value will fail.
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
attribute. Such objects are linked in a
different area of memory and are not altered by the runtime startup code.