Mail Archives: djgpp/1999/05/22/18:29:42
Radu Georgescu aka skoola wrote:
>
> > > the static and the automatic variables are located in memory one next to
> > > another, if they are declared so
> >
> > This is simply not true. Static variables go to the data section
> > while automatic variables are on the stack. So they could be
> > megabytes apart. You can easily verify that by taking an address of a
> > variable and printing it.
>
> you didn't understand what i'm talking about. you have to know the address of
> one static variable and then you can address the others using the following
> model:
> static short a,b;
> asm("
> mov 2+%0,%%ax
> "
> :
> :"g"(a));
> and you get
>
> mov b,ax
>
> if both a and b are automatic variables, you may also do this stuff but there
> should be -2+%0 instead 2+%0 ,IMHO
NO. This may work now but you CANNOT depend on it. The compiler is at
liberty to place variables wherever it wants. There is absolutely
nothing requiring it to put variables declared together adjacent to each
other.
This is even more so for auto variables. One or both may be put in
registers or even optimized entirely out of existence.
If you want to know where a variable lives, you have to ask the
compiler. Plain and simple.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -