Declaration within a loop.

Tom Neff tneff at bfmny0.UU.NET
Thu Sep 28 02:18:09 AEST 1989


In article <559 at crdos1.crd.ge.COM> davidsen at crdos1.UUCP (bill davidsen) writes:
>  Most C compilers allocate space on the stack for this when the
>procedure is entered.  It therefore is not a practical thing to do to
>save space. 

For what it's worth AT&T's pcc on V/386 does share reuse stack space
among all temp in-block variables.  Intel's C compiler does not though.
I'm sure there are tons of other examples pro and con.

>             The most common use is to correct for having forgotten to
>declare a variable at the start of a procedure.

Here I must disagree.  The most common and obvious use of an in-block
temp is to restrict scope!  Unless one's editor lacks a "move up"
command there is no reason to declare a variable locally within a block
just because one "forgot" to declare it function-wide!  The declaration
is as easily added in one place as the other.  But it may be quite
important to ensure that "i" or "swaptmp" is unheard-of outside the
local block.
-- 
Annex Canada now!  Free Quebec; raze and depopulate  |  Tom Neff
Ontario; license Inuit-run casinos on the BC shore.  |  tneff at bfmny0.UU.NET



More information about the Comp.lang.c mailing list