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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1,367 Views
tommy1231
Contributor II
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;}

 
 
Labels (1)
0 Kudos
2 Replies

373 Views
CompilerGuru
NXP Employee
NXP Employee
Check the SmartLinker manual (a chapter in "CW for HC12 V4.5\Help\pdf\Build_Tools_Utilities.pdf")
for ENTRIES, it can be used to allocate otherwise unused objects.

But at least for this sample code, the reasonable (and portable, and "C" style) way is to use an array, and not 6 individual variables. But of course this is only a sample and discussing style questions in samples is a bit pointless :smileyhappy:.

Daniel

0 Kudos

373 Views
tommy1231
Contributor II
Daniel,
 
Thanks for the help that worked.
 
Tom
0 Kudos