Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!iuvax!ux1.cso.uiuc.edu!aries!mcdonald From: mcdonald@aries.scs.uiuc.edu (Doug McDonald) Newsgroups: comp.lang.c Subject: Re: When should variables within blocks be allocated? Message-ID: <1990Jan19.224633.22564@ux1.cso.uiuc.edu> Date: 19 Jan 90 22:46:33 GMT References: <253@usblues.UUCP> <26449@stealth.acf.nyu.edu> Sender: news@ux1.cso.uiuc.edu (News) Distribution: usa Organization: Univ. of Illinois at Urbana-Champaign, Chemical Sciences Lines: 28 In article <26449@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes: >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. > I just tried it on the new compiler that arrived in the mail yesterday. giving it the program void sub() { while (0) { int j[1000000],i; for (i = 0; i < 1000000; i++) j[i] = i; } } resulted in no data allocation and the generated code ret which is a pretty small function. MicroWay NDPC 2.00 for the 386. Exchanging the while(0){ and int j[... lines gave the same result. The VMS C compiler has been this good for quite a while. Doug McDonald (mcdonald@aries.scs.uiuc.edu)