... Show me a compiler and platform with a stack where this
technique [i.e., taking the address of a local automatic-storage
variable, pretending it is a pointer to an array of such variables,
and indexing out of bounds in that nonexistent array]
does not work. Then we'll talk.
Try it on a Pyramid; you may be surprised.
(The Pyramids has TWO stacks, and it is difficult to predict which
stack an automatic variable will be on. So, even if you somehow
"know" the distance between stack frames, you may not find the
other variable(s) you expect.)
And why don't you be constructive, and show me another way to answer the
original poster's question.
There *are* no good answers to the OP's question (which seems to
have disappeared -- what happened to useful context? -- but which
I recall as being something like this):
"You are given a function f() that has an automatic variable x.
If f() calls g(), but does not pass g() the address of x, and
does not take the address of x anywhere, and does not store a
return value from g() into x, how can you reliably modify x
from within g()?"
The answer is: you cannot. Compilers move variables around all the
time. A compiler that sees that f() never modifies x after it is
assigned an initial value may actually *remove* x, replacing all
later references to x with the value that was stored earlier.
In short, the OP wants a good way to shoot himself in the foot;
and the replies have pointed out that shooting yourself in the foot
is a bad idea. And indeed, it *is* a bad idea -- the compiler may
not be using a .22, but a .45, and the hydrostatic shock could kill
you.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to