Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!jarthur!uci-ics!gateway From: rfg@paris.ics.uci.edu (Ronald Guilmette) Newsgroups: gnu.gcc Subject: A question on local variable allocation Message-ID: <25E58087.11649@paris.ics.uci.edu> Date: 23 Feb 90 18:27:19 GMT Organization: UC Irvine Department of ICS Lines: 43 Can someone please explain to me why, in the following code, the space allocated for the two local array variables does not overlap? Is there some little rule in the ANSI C standard that would require such treatment? It would seem to me that it is not necessary, and that it can result in a waste of space, and also possibly slower execution (due to increased paging and an increase in cache misses). I am posting this question to gnu.gcc rather than the gnu.gcc.bug group because this is *not* a bug. The code certainly works "correctly" given the allocation strategy that GCC is now exibiting. My question is "Would the code still work correctly even if GCC practiced overlaping allocation for local variables in disjoint local scopes?" If so, why has this not been implemented. Superfically, it would seem to be a simple thing to do. (Of course I acknowledge that things always seem that way as long as you are not the guy who has to roll up his sleeves and get in and do it.) (Note: In the following example, the function calls are only in there to make sure that the arrays to not get optimized away entirely.) extern void g(); void function () { { int inside1[1024]; g (inside1); } { int inside2[1024]; g (inside2); } } // Ron Guilmette (rfg@ics.uci.edu) // C++ Entomologist // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.