From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: ** X-Spam-Status: No, score=2.1 required=5.0 tests=BAYES_20,HEADER_SPAM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b30bd69fa8f63cb2 X-Google-Attributes: gid103376,public X-Google-Thread: fc772,b30bd69fa8f63cb2 X-Google-Attributes: gidfc772,public X-Google-ArrivalTime: 2003-06-14 17:05:19 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!xmission!news-hog.berkeley.edu!ucberkeley!enews.sgi.com!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in-maxim.spamkiller.net!usc.edu!rpi!not-for-mail From: brangdon@cix.co.uk (Dave Harris) Newsgroups: comp.lang.ada,comp.lang.c++.moderated Subject: Re: C bug of the day Date: 14 Jun 2003 20:07:33 -0400 Organization: unknown Sender: cppmods@netlab.cs.rpi.edu Message-ID: References: Reply-To: brangdon@cix.co.uk NNTP-Posting-Host: netlab.cs.rpi.edu X-Original-Date: Sat, 14 Jun 2003 12:40 +0100 (BST) X-Submission-Address: c++-submit@netlab.cs.rpi.edu X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated iQBVAwUAPuu4wkHMCo9UcraBAQEtIgH/X6vcyD+reeS01xLAWyWH7yCquPOUReQK I7bf1CfV2N5vFktWVknnp8ni0fqEQZ5N3+7f2ki8yM0aVF8sxdX1Ew== =1JjM Xref: archiver1.google.com comp.lang.ada:39185 comp.lang.c++.moderated:68362 Date: 2003-06-14T20:07:33-04:00 List-Id: ron@sensor.com (Ron Natalie) wrote (abridged): > int i; // initialize to 0 > stream >> i; > > auto int i; // recycle auto to mean uninitialized. > stream >> i; > > In the above case existing code that used the unqualified name > would work in old and new compilers (with a slight performance > hit in the new complier), those in the second case would work > the same way in the old and new compiler (the same way it used > to). A good optimiser could emit the same code in both cases. The value zero is never read, so never needs to be written. The compiler could figure this out either from the source (eg if stream is from a template) or from knowing the semantics of the std library (if stream is from the std). Cases where zero- initialisation cannot be optimised away are fairly rare - although sometimes important when they do arise. If we actually need zeros, it may be more efficient to let the compiler provide them. For example, with an instance of a deep class hierarchy, the compiler can zero-initialise all of the instance variables with a single memset(), instead of every class needing its own set of assignments. Indeed, it can make sense to push the nulling even further back, and have a "nulled heap". Then the system can do the work of writing nulls during its idle time. -- Dave Harris, Nottingham, UK [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ] [ about comp.lang.c++.moderated. First time posters: do this! ]