When should variables within blocks be allocated?

brnstnd at stealth.acf.nyu.edu brnstnd at stealth.acf.nyu.edu
Fri Jan 19 09:17:33 AEST 1990


In article <253 at usblues.UUCP> tom at usblues.UUCP (Tom Markson) writes:
> The .s file indicates that all stack space is allocated at the start of a 
> function.  

If a function contains the statement if(0) { int k[100000000]; ... },
should the space for k be allocated? Every compiler I've tried allocates
variables at function entry like Tom's, but it would be nice to save
100M of memory if k is never used. I can't find any ANSI rules on this.

If the answer is that the space for k can be ignored, are there any
compilers smart enough to optimize k away? Are there any compilers that
go all the way and allocate k the moment they enter the block? Is the
space saved worth the efficiency loss?

---Dan



More information about the Comp.lang.c mailing list