How could CONST data will not be compiled to be immediate data in code?

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

How could CONST data will not be compiled to be immediate data in code?

跳至解决方案
1,250 次查看
elvan
Contributor I

I am working in a calibration projector. for realtime setting, I don't want that CONST data is compiled to immediate data.

what can I do .

in this case,  b = a is compiled to  b = 200  in ASM.

C:          const u16  a = 200
             b = a;

ASM:    14fc: 22c8       movs r2, #200 ; 0xc8
             14fe: 4b04       ldr r3, [pc, #16] ; (1510 <ini_fs_misc+0x24>)
             1500: 801a       strh r2, [r3, #0]

S32DS V1.3 + Win10

标签 (1)
0 项奖励
1 解答
1,084 次查看
stanish
NXP Employee
NXP Employee

Hi elvan,

One solution could be to declare the const as a volatile. This way you basically disable compiler optimizations  for this const.

C: volatile  const u16  a = 200

Or access the value of the constant via pointer:

C:

const unsigned short a = 200;
unsigned short *pa = &a;


b=*pa;

Hope it helps.

S.

在原帖中查看解决方案

0 项奖励
3 回复数
1,085 次查看
stanish
NXP Employee
NXP Employee

Hi elvan,

One solution could be to declare the const as a volatile. This way you basically disable compiler optimizations  for this const.

C: volatile  const u16  a = 200

Or access the value of the constant via pointer:

C:

const unsigned short a = 200;
unsigned short *pa = &a;


b=*pa;

Hope it helps.

S.

0 项奖励
1,084 次查看
elvan
Contributor I

Hi Stanislav.

Thank you very much , it's very useful.

0 项奖励
1,084 次查看
elvan
Contributor I

Developing on the KEAZ128

0 项奖励