Is there any way to temp switch off dead code elimination via #pragma?

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

Is there any way to temp switch off dead code elimination via #pragma?

Jump to solution
1,353 Views
Koyuki
Contributor I
I'm using HCS12, and for some reason I need to put a bunch of global variables into the CONST_SEG, hence I define them as "const". Those variables are actually referred via API functions, hence within the project they are only assigned with initial values. But I don't want the CodeWarrior to eleminate them during optimization, so I declare them as "extern" in some header file, or define them as "volatile". But this looks not quite good actually, for the modification of these variables are via some hardware path, not the normally way of global variable usage. So I wanna try use some #pragma to switch off the code optimization only on these variables. Is it possible? If so, which #pragma shall I use then?
Labels (1)
Tags (1)
0 Kudos
1 Solution
621 Views
Nouchi
Senior Contributor II
Hi,

The best way to force linker to link unused variables, is probably to add the name of your variable in ENTRIES section of your prm file:
in your C file:
const char yourVar1[10] = "Your data";


in your prm file below NAME section:
ENTRIES
yourVar1, yourVar2, ....
END


Emmanuel

View solution in original post

0 Kudos
1 Reply
622 Views
Nouchi
Senior Contributor II
Hi,

The best way to force linker to link unused variables, is probably to add the name of your variable in ENTRIES section of your prm file:
in your C file:
const char yourVar1[10] = "Your data";


in your prm file below NAME section:
ENTRIES
yourVar1, yourVar2, ....
END


Emmanuel
0 Kudos