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.

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.

Note: Initialized 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 (see Persistent Type 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 (see Status Register Preservation).