Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!umich!yale!cmcl2!stealth.acf.nyu.edu!brnstnd From: brnstnd@stealth.acf.nyu.edu Newsgroups: comp.lang.c Subject: When should variables within blocks be allocated? Message-ID: <26449@stealth.acf.nyu.edu> Date: 18 Jan 90 22:17:33 GMT References: <253@usblues.UUCP> Reply-To: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Distribution: usa Organization: IR Lines: 15 X-Original-Subject: Re: Is goto safe? In article <253@usblues.UUCP> tom@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