When should variables within blocks be allocated?

Doug McDonald mcdonald at aries.scs.uiuc.edu
Sat Jan 20 09:46:33 AEST 1990


In article <26449 at stealth.acf.nyu.edu> brnstnd at 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 at aries.scs.uiuc.edu)



More information about the Comp.lang.c mailing list