Tom Christiansen

Global Constants not being allocated (Put in UNUSED-OBJECTS)

Discussion created by Tom Christiansen on May 22, 2007
Latest reply on May 23, 2007 by Tom Christiansen
I am trying to create a bunch of constants and then use a pointer to point to them.  However since I do not use the constants in my code they are optimized out. 
 
here is an example:
 
The linker only allocates Variable0 in ROM.  The rest of them are listed in the unused-objects section of the memory map.  Any suggests on how to keep the linker from removing these would be appreciated.

Code:
typedef struct{   unsigned char Type;   unsigned long DefaultValue;} Variable_Properties_;const Variable_Properties_ Variable0 = {0, 500};const Variable_Properties_ Variable1 = {1, 5000};const Variable_Properties_ Variable2 = {2, 50000};const Variable_Properties_ Variable3 = {3, 500000};const Variable_Properties_ Variable4 = {4, 5000000};const Variable_Properties_ Variable5 = {5, 50000000};Variable_Properties_       *far VariableProperties;void temp_function(void){   Variable_Properties_ temp;   //pointer points to the first one   VariableProperties = &Variable0;   //this should load 4    temp.Type = VariableProperties[4].Type;   //this should load 5000000    temp.DefaultValue= VariableProperties[4].DefaultValue;}

 
 

Outcomes