Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!adm!I1090801%DBSTU1.BITNET@CUNYVM.CUNY.EDU
From: I1090801%DBSTU1.BITNET@CUNYVM.CUNY.EDU
Newsgroups: comp.lang.c
Subject: Re: How are local vars allocated?
Message-ID: <10572@brl-adm.ARPA>
Date: Sun, 29-Nov-87 07:41:37 EST
Article-I.D.: brl-adm.10572
Posted: Sun Nov 29 07:41:37 1987
Date-Received: Tue, 1-Dec-87 05:54:39 EST
Sender: news@brl-adm.ARPA
Lines: 32

I think there is a good reason for a C-compiler to allocate
space for all local variables at the beginning of a function.
Look at the following example:
int f()
{
     if (...)
     {    int a;
          ...
          goto label2;
  label1: ...                 /* do someting with a */
     }
     else
     {    int b;
          ...
          goto label1;
  label2: ...                /* do something with b */
     }
}
In this case it is not possible to allocate the same space
for the variables a and b. If you allocate space for a at the
start of the then-block there is no space allocated for variable
b after you do the jump into the else-part (at least not until
the compiler does some very tricky code generation).
    Another reason for allocating space at the beginning of
a function is the gain in code-space and runtime (but perhaps
with a loss of data-space, which may only become a problem in
recursive calls).

                                      Ulf Gruene
                                I1090801@DBSTU1.BITNET
                         Technische Universitaet Braunschweig
                                     West Germany