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=-0.5 required=5.0 tests=BAYES_00,HEADER_SPAM, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII 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-16 15:48:32 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!uwm.edu!rpi!not-for-mail From: kanze@gabi-soft.fr Newsgroups: comp.lang.ada,comp.lang.c++.moderated Subject: Re: C bug of the day Date: 16 Jun 2003 18:50:42 -0400 Organization: http://groups.google.com/ Sender: cppmods@netlab.cs.rpi.edu Message-ID: References: NNTP-Posting-Host: netlab.cs.rpi.edu X-Original-Date: 16 Jun 2003 02:46:30 -0700 X-Submission-Address: c++-submit@netlab.cs.rpi.edu X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated iQBVAwUAPu5JuUHMCo9UcraBAQGiswIAiD4JmSzLODlE6iV8xiONW4MvJ/vggcfg eTU/pprVmQ1lZkHNOitkFmnA4aqfbwJ9rwE8jAlTUEFdpfiskPLBhg== =jeSt Xref: archiver1.google.com comp.lang.ada:39294 comp.lang.c++.moderated:68473 Date: 2003-06-16T18:50:42-04:00 List-Id: brangdon@cix.co.uk (Dave Harris) wrote in message news:... > 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. But only because it is allowed to have special knowledge of std::istream. If you are dealing with a user defined stream, it can't. > The value zero is never read, so never needs to be written. But if operator>>( MyStream&, int& ) is in another translation unit, how can the compiler know this? > 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. I've long thought that a useful optimization for a compiler would be to work out the image of the local variables after initialization, generate a static block with the same image, and replace the initialization code by a memcpy. For C, I'm sure this would help; for C++, where initialisation in normally in the form of constructors (defined in other translation units), I'm less convinced. -- James Kanze GABI Software mailto:kanze@gabi-soft.fr Conseils en informatique orient�e objet/ Beratung in objektorientierter Datenverarbeitung 11 rue de Rambouillet, 78460 Chevreuse, France, T�l. : +33 (0)1 30 23 45 16 [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]