C99: Suggestions for style(9)
Peter Jeremy
peter at vk2pj.dyndns.org
Sun May 3 18:59:57 UTC 2009
On 2009-Apr-29 12:10:44 -0700, John Gemignani <john.gemignani at isilon.com> wrote:
>Are local variables allocated on-the-fly on the stack or does the
>compiler preallocate the space on entry?
This is compiler and optimisation dependent. As a general rule, if a
compiler is not performing any optimisation, it is likely to allocate
all variables on the stack. An obvious code optimisation is to keep
variables in registers instead of storing them on the stack.
In the specific case of older gcc versions with optimisation enabled
(I'm not sure of the behaviour of gcc 4.x), gcc will immediately spill
(allocate on the stack) local variables that aren't eligible to be
held in registers (eg too large or the variable address is taken) and
allocate remaining variables to virtual registers. During code
generation, virtual registers are mapped to physical registers and any
remaining virtual registers are allocated on the stack.
> If I have to delve into a
>crashdump, having the variables on the big entry allocation has been
>very helpful in the past.
OTOH, not caching variables in registers has a significant adverse
impact on performance.
--
Peter Jeremy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20090503/510d1e1f/attachment.pgp
More information about the freebsd-hackers
mailing list