From owner-freebsd-hackers Tue May 20 09:50:43 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id JAA12747 for hackers-outgoing; Tue, 20 May 1997 09:50:43 -0700 (PDT) Received: from dg-rtp.dg.com (dg-rtp.rtp.dg.com [128.222.1.2]) by hub.freebsd.org (8.8.5/8.8.5) with SMTP id JAA12742 for ; Tue, 20 May 1997 09:50:40 -0700 (PDT) Received: by dg-rtp.dg.com (5.4R3.10/dg-rtp-v02) id AA01050; Tue, 20 May 1997 12:50:05 -0400 Received: from ponds by dg-rtp.dg.com.rtp.dg.com; Tue, 20 May 1997 12:50 EDT Received: from lakes.water.net (lakes [10.0.0.3]) by ponds.water.net (8.8.5/8.7.3) with ESMTP id HAA25686; Tue, 20 May 1997 07:10:51 -0400 (EDT) Received: (from rivers@localhost) by lakes.water.net (8.8.5/8.6.9) id HAA25363; Tue, 20 May 1997 07:18:11 -0400 (EDT) Date: Tue, 20 May 1997 07:18:11 -0400 (EDT) From: Thomas David Rivers Message-Id: <199705201118.HAA25363@lakes.water.net> 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 Content-Type: text Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk > >> 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 -