Path: utzoo!mnetor!uunet!mcvax!unido!iaoobelix!woerz
From: woerz@iaoobelix.UUCP
Newsgroups: comp.lang.c
Subject: Re: How are local vars allocated? - (nf)
Message-ID: <6700014@iaoobelix.UUCP>
Date: 30 Nov 87 16:20:00 GMT
References: <7401@prls.UUCP>
Lines: 51
Nf-ID: #R:prls:-740100:iaoobelix:6700014:000:1818
Nf-From: iaoobelix!woerz    Nov 30 17:20:00 1987

> /***** iaoobelix:comp.lang.c / brl-adm!I1090801%DBSTU1.BITNET@CU /  1:41 pm  Nov 29, 1987*/
> 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).

I think that it is possible in this case, if you use a label the same
way you use the normal entry to a block. That is you have to allocate
space if you hit a label and there are local variables for that block.
You will have to jump around the code, if you entered the block at
another entry. I'm not saying that this is worth to do, but I think
that it's doable without some tricky code generation.

> ...
>
>                                       Ulf Gruene
>                                 I1090801@DBSTU1.BITNET
>                          Technische Universitaet Braunschweig
>                                      West Germany
> /* ---------- */

------------------------------------------------------------------------------

Dieter Woerz
Fraunhofer Institut fuer Arbeitswirtschaft und Organisation
Abt. 453
Holzgartenstrasse 17
D-7000 Stuttgart 1
W-Germany

BITNET: iaoobel.uucp!woerz@unido.bitnet
UUCP:   ...{uunet!unido, pyramid}!iaoobel!woerz