Keil™, An ARM® Company

Discussion Forum

variables at same memory places

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
arto malm
Posted
15-May-2008 02:19
Toolset
C51
New! variables at same memory places

I have declared in source file src1.c following variables.

xdata unsigned char keybuffer[8];
unsigned int keys;
unsigned char keyctr;


I have an another source file src2.c and I want to declare
variables into same memory places.

How can I declare in src2.c variables into same memory area with
variables in src1? I know that my software do not use variables declared in src1.c in this case.

Is there something like following way to use?

extern unsigned char keyctr;
unsigned char var2 _at_ keyctr; //compiler does not accept this.

regards
Arto

Read-Only
Author
arto malm
Posted
15-May-2008 02:55
Toolset
C51
New! Additional question!

Actually I want to declare unsigned long(four bytes)long variable into same memoryarea(keybuffer[8]) in src1.c.

In src2.c I want to do following:

unsigned long var32 _at_ keybuffer[3]; //does not compile.

regards
Arto

Read-Only
Author
Per Westermark
Posted
15-May-2008 03:20
Toolset
C51
New! RE: Additional question!

Why not use the C way of declaring overlayed variables - the union? That works with all compilers, and since it is clearly visible in the source code, the next developer to handle the source code will not get any bad surprises that his variables may be overwritten by other functions.

Read-Only
Author
Hans-Bernhard Broeker
Posted
15-May-2008 15:21
Toolset
C51
New! RE: variables at same memory places

I know that my software do not use variables declared in src1.c in this case.

Then those variable don't deserve having external linkage in src1.c. Odds are they shouldn't even have file scope inside src1.c.

You're basically trying to outsmart the linker's overlay analysis. Are you sure you're up to it?

Read-Only
Author
arto malm
Posted
16-May-2008 00:11
Toolset
C51
New! RE: variables at same memory places

Yes, you are absolutely right. I thought that also and it is better to belive linker analysis feature. Using of union is of course one possibility(mentioned in previous answer).
Thanks everybody for answers.

Next Thread | Thread List | Previous Thread Start a Thread | Settings