Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 May 1997 07:18:11 -0400 (EDT)
From:      Thomas David Rivers <ponds!rivers@dg-rtp.dg.com>
To:        ponds!zeta.org.au!bde, ponds!FreeBSD.ORG!hackers, ponds!uriah.heep.sax.de!j, ponds!lakes.water.net!rivers
Subject:   Re: Variable initialization
Message-ID:  <199705201118.HAA25363@lakes.water.net>

next in thread | raw e-mail | index | archive | help
> >> With old compilers, it was a pessimization to initalize variables
> >> unnecessarily or long before they are used.  With modern compilers,
> >> it defeats automatic checking for uninitialized variables and may
> >> still prevent some optimizations.  
> >
> > Err, umm; just a nit - I would note that it defeats the check by
> >initializing the variable; thus, it's not uninitialized :-) :-)
> >What optimizations were you considering?
> 
> Ones based on variable liftime analysis.  If the compiler would emit
> a spurious warning because it can't tell that a variable is initialized
> for all flows of control, then initializing the variable when it is
> declared (or just early) is a pessimization - the compiler must store
> the value to memory or uselessly extend a register lifetime to hold
> the (unused) initial value.  The correct fix for this is to rearrange
> the code so that both compilers and humans can understand the flow of
> control or to out up with the warning.  Adding an unused initialization
> would further obfuscate the flow of control.
> 
> Bruce
> 

 Ahh... but forward flow operations would move the initialization to
the beginning of the basic block where it's used.

 i.e. If a variable has the same value in the IN and OUT sets,
and is unused  in the block - it is hoisted through it.

 Initializing a variable "early" actually doesn't affect too much
of a change... and can be viewed as initializing it at the start of the
first basic block where it's referenced.

 So - control flow really isn't too much of an issue here, the register
lifetime isn't extended and the variable is (presumable correctly)
initialized.  

 I believe, of course, some of the other arguments far outweigh
this concern - personally, I much prefer initializations that are
performed outside of the declaration block... for about the same
reasons cited.

	- Dave Rivers -





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199705201118.HAA25363>