Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!clyde!watmath!orchid!rbutterworth From: rbutterworth@orchid.waterloo.edu (Ray Butterworth) Newsgroups: comp.lang.c Subject: Re: block variables Message-ID: <11742@orchid.waterloo.edu> Date: Thu, 19-Nov-87 08:41:27 EST Article-I.D.: orchid.11742 Posted: Thu Nov 19 08:41:27 1987 Date-Received: Sun, 22-Nov-87 10:38:59 EST References: <189@dalcsug.UUCP> <102600020@datacube> <6692@brl-smoke.ARPA> Organization: U of Waterloo, Ontario Lines: 48 In article <6692@brl-smoke.ARPA>, gwyn@brl-smoke.ARPA (Doug Gwyn ) writes: > Actually, most reasonable compilers allocate enough space for the > deepest contained block at entry to a function, then when execution > enters the block, the preallocated space is simply used without > having to perform any explicit allocation at that point. Don't you mean "UNreasonable"? (or does "reasonable" refer to the fact that this is done by some "infinite stack" C compilers, and you consider having an infinite stack reasonable?) Consider a recursive function: recurse(x) { auto int y; auto int z; { auto int temparray[10000]; /*calculation of y and z using x*/ } if (y) recurse(y); if (z) recurse(z); } Admittedly it's not the most useful function in the world, and the calculation could be moved to another function, but a "reasonable" compiler would make the recursive call only leaving enough room on the stack for the autos y and z, and any overhead associated with making the call, say a dozen bytes. The compiler you describe (e.g. BSD 4.3) would waste 40000 bytes for every level of recursion. The "allocation" for each block could be done at compile time, not at execution time, so there wouldn't be any loss of cpu efficiency. Besides, the "preallocate the most you'll ever need" approach only encourages code such as this (excerpted from the BSD source for VI): if (lhs[0] == '#') { char funkey[3]; funkey[0] = 'f'; funkey[1] = lhs[1]; funkey[2] = 0; dname = funkey; } addmac(lhs,rhs,dname,mp); On a different compiler, dname would be pointing at garbage when addmac is called.