Keep variables in order. CW 10.2, Kinetis K60

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

Keep variables in order. CW 10.2, Kinetis K60

Jump to solution
451 Views
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 !!

Labels (1)
Tags (3)
0 Kudos
1 Solution
362 Views
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.

View solution in original post

0 Kudos
2 Replies
363 Views
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 Kudos
362 Views
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 Kudos