This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Why auto variables NOT overlap on stack?
- From: Ding Curie <ding dot curie at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 4 Feb 2010 10:02:46 +0800
- Subject: Why auto variables NOT overlap on stack?
Hello, everyone!
I'm with the latest MinGW, and following program:
-----------------------------------------------------------------------
char *p1, *p2;
int main(void)
{
{
char a[1024];
p1 = &a[0];
}
{
char a[1024];
p2 = &a[0];
}
printf("p1 - p2 = %d\n", p1 - p2);
return 0;
}
-----------------------------------------------------------------------
output:
> p1 - p2 = 1024
(Optimize or not makes no difference.)
That means the two arrays don't overlap on the stack. But since that
will save a significant amount of stack space, I wonder, why gcc don't
manage to make the two arrays share one same memory block of 1K bytes
on the stack?
BTW, I checked two embedded C compilers: CCS from TI and VisualDSP
from ADI, do the trick, outputing p1 - p2 = 0.
Thanks in advance.
Ding Curie