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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
1,350 次查看
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?
标签 (1)
标记 (1)
0 项奖励
1 解答
618 次查看
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 项奖励
1 回复
619 次查看
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 项奖励