There were a few bugs in the code examples that have been fixed.
The loop in startup.c
function _startup()
that calling each entry
from __init_array_start
to __init_array_end
was incorrect in
Startup Code in C and Startup Code in
C++. It has been fixed and tested.
To test it the main.c
routine was updated to demonstrate the operation of the
contructors called in _startup()
before main()
is called.
The corrected C code is below:
Some test code was added to main.c
.
A trace shows both variables written before main is reached.
global_value1_with_constructor
is initalized to00000001
in thememcpy()
frommetal_segment_data_source_start
.- Startup iterates over
__init_array_start
to__init_array_end
. - When
setup_global1()
is called it is set to00100001
. - When
setup_global2()
is called it is set to00100201
.