Topic : RC51 - Are variables local to a function overlaid?

Forum : 8051

Original Post
Post Information Post
February 15, 2007 - 6:08pm
Guest

For example, in the following, the uses of 'a' and 'b' don't overlap

int g1, g2

void foo(void)
{
int a, b;

a = g1 * g1;
g1 = a + g1;

b = g2 / g1;
g2 = b * b;
}

Will RC51 give then the same location in xdata or idata, or are they always separate in memory?

regards Steven Pruzina

Replies
Post Information Post
+1
0
-1
February 16, 2007 - 1:51pm
Guest

The overlay mechanism is managed only by the linker. The compiler does not manage overlay.
However, the compiler could relocate a variable into a register (a couple of registers for a 16-bit value) when there are some available registers (but here the 16-bit multiply requires all the registers). In that case, the same register could be used by different variables. If, during its lifetime, a variable is used only in registers (it could be several registers depending on the portion of code), no data/xdata will be reserved for this variables.
Francis