This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Memory layout (novice questions).
- To: Virgil dot Palanciuc at cs dot pub dot ro
- Subject: Re: Memory layout (novice questions).
- From: Mike Stump <mrs at windriver dot com>
- Date: Mon, 24 Apr 2000 12:16:43 -0700 (PDT)
- Cc: gcc at gcc dot gnu dot org
> From: "Virgil Palanciuc" <Virgil.Palanciuc@cs.pub.ro>
> To: "Gcc@Gcc. Gnu. Org" <gcc@gcc.gnu.org>
> Date: Sun, 23 Apr 2000 15:44:33 +0300
> I would like to rearrange the variables in a function, in order to
> place the smaller first.
Why? What you want to ask is a different question, one probably
better suited to comp.lang.c, but I don't know what that question is.
I'd rather answer your real question, than this one. It might have a
better answer than this one.
> there is no way to ask gcc to do this (please correct me if I am
> wrong).
Well, you can almost do this. Put everything in a structure with the
exact layout you want, and then declare a variable of the structure
type. This will get you the relative layout. From there, there isn't
a way to get it to be at a certain sp offset. You can just guess and
try various things, but if the compiler wants to put it too far out of
the stack for your tastes, you're just out of luck. If it is too far
into the stack, you can add char [N] before it, to try and move it,
varying N until it hits the placement you want. This trick isn't
portable, isn't documented, and won't work across targets, or across
compiler versions, unless you just have some more blind luck.
Happy hanging, uhm, I mean coding...