storage variable in the specific location in memory

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

storage variable in the specific location in memory

1,701 次查看
VeronicaFNX
Contributor I

Hello,
how I can storage variable in the specific location in memory?
For example I have

char variable;      //I want have variable on address 0x2000 1500

but how it say to compiler?
I'm using Code warrior 6.3 and m52233demo
please help.
Regards
               Vero

标签 (1)
0 项奖励
回复
2 回复数

775 次查看
mccPaul
Contributor I

Hi Vero,
 
If you declare an automatic variable in a function it will be created somewhere on the heap, if it is a static variable, it will be in the bss section of your linked binary. In both cases there is no way in C to make the compiler create a variable at a specific location.
 
What you can do is create a pointer variable and set that to point to the location you wish to use:
Code:
char *p_variable;p_variable = 0x20001500;// Now you just dereference the pointer to access your char// e.g. to set the variable to *:*p_variable = '*';

 
It is a good idea to declare this type of variable in your linker command file, along with your other memory map declarations in the way that Simon has pointed out.
 
Cheers,
 
Paul.

Message Edited by mccp on 2007-03-1510:02 AM

Message Edited by mccp on 2007-03-1510:03 AM

0 项奖励
回复

775 次查看
SimonMarsden_de
Contributor II
Hi Vero

You can use the Linker Control File (LCF) to do this. Have a look at the following thread, where a similar question was discussed:

http://forums.freescale.com/freescale/board/message?board.id=CFCOMM&message.id=1578#M1578


In particular, the second and third posts in this thread gives some details which might be helpful.

Good luck


Simon
0 项奖励
回复