SPRU514Z July 2001 – October 2023 SM320F28335-EP
Static and global variables of type const without explicit initializations are similar to other static and global variables because they might not be preinitialized to 0 (for reasons discussed in Section 6.13). For example:
const int zero; /* might not be initialized to 0 */
However, the initialization of global const variables is different because these variables are declared and initialized in a section called .econst or .const (depending on the ABI). For example:
const int zero = 0 /* guaranteed to be 0 */
For COFF, this corresponds to an entry in the .econst section:
.sect .econst
_zero
.word 0
For EABI, this corresponds to an entry in the .const section:
.sect .const
zero
.word 0
This feature is particularly useful for declaring a large table of constants, because neither time nor space is wasted at system startup to initialize the table. Additionally, the linker can be used to place the .econst or .const section in ROM.
You can use the DATA_SECTION pragma to put the variable in a section other than .econst or .const. For example, the following C code:
#pragma DATA_SECTION (var, ".mysect")
const int zero=0;
is compiled into this assembly code (in COFF mode):
.sect .mysect
_zero
.word 0