R
Roberto Waltman
^Keith Thompson said:I just tried something similar:
================================
#include <stdio.h>
void set_registers(void)
{
register int x0, x1, x2, x3, x4, x5, x6, x7, x8, x9;
x0 = 100;
x1 = 101;
x2 = 102;
x3 = 103;
x4 = 104;
x5 = 105;
x6 = 106;
x7 = 107;
x8 = 108;
x8 = 109;
x9 not initialized.
Your findings are still valid.
}
void read_registers(void)
{
register int y0, y1, y2, y3, y4, y5, y6, y7, y8, y9;
printf("%d %d %d %d %d %d %d %d %d %d\n",
y0, y1, y2, y3, y4, y5, y6, y7, y8, y9);
}
int main(void)
{
set_registers();
read_registers();
return 0;
}
================================
On most compilers and platforms, I got garbage output. But using
Sun's C compiler on Solaris/SPARC, I got the following output:
100 101 102 103 104 105 106 107 -12788660 200
Apparently the compiler re-used the same 8 registers for the first 8
"register" variables in each function, and didn't clobber them between
the calls.
You could do the same thing using something like "static register"
variables if there were such a thing.
Yes. I thought of the similarity to global/static variables in a
previous post. Did not mention it because I was not sure if the
analogy breaks somewhere.
Roberto Waltman
[ Please reply to the group,
return address is invalid ]