Keep variables in order. CW 10.2, Kinetis K60

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

Keep variables in order. CW 10.2, Kinetis K60

跳至解决方案
1,147 次查看
carlosburgos
Contributor I

Hi. There are some way to keep all variables declares in my program in the same order in the memory ?

 

I want to be able to copy blocks of memory with pointers.
But I need that the variables keep in the Ram in the same order that I them declare in the program

 

Example:

 

char a;

char b;

char c;


I need the correlative address

 

address    size          type   variable

 

1FFF0000 00000001 .dat a

1FFF0001 00000001 .dat b

 

1FFF0002 00000001 .dat c

 

 

I'm workign with CW 10.2, kinetis k60 MCU.


Recently I have changed to kinetis. Before it was working with keil with 8051 MCU. In the uvision ther are the paremetrer  " - order " in the compiler, but in CW  I don't know.

 


Thanks !!

标签 (1)
标记 (3)
0 项奖励
回复
1 解答
1,058 次查看
BlackNight
NXP Employee
NXP Employee

Hi,

At least in the C/C++ programming language, you cannot rely on the order of variables, as the linker might change it (e.g. if a variable is not used/etc).

If you rely on the order, then I suggest you put the variables inside a struct.

The other way is that you place the objects into sections and do the placement in the linker, but this might be a lot of work if you do it that way. So I would put them into a struct.

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,059 次查看
BlackNight
NXP Employee
NXP Employee

Hi,

At least in the C/C++ programming language, you cannot rely on the order of variables, as the linker might change it (e.g. if a variable is not used/etc).

If you rely on the order, then I suggest you put the variables inside a struct.

The other way is that you place the objects into sections and do the placement in the linker, but this might be a lot of work if you do it that way. So I would put them into a struct.

0 项奖励
回复
1,058 次查看
carlosburgos
Contributor I

Hi Erich,

I will change everything to structures. I need to have them in order to copy in blocks to external memories, etc..


It's a work, but less than put all in sections.

Thanks  !!

0 项奖励
回复