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.2 required=5.0 tests=BAYES_00,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: fc772,b30bd69fa8f63cb2 X-Google-Attributes: gidfc772,public X-Google-Thread: 103376,b30bd69fa8f63cb2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-16 02:04:23 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!logbridge.uoregon.edu!uwm.edu!rpi!not-for-mail From: John Potter Newsgroups: comp.lang.ada,comp.lang.c++.moderated Subject: Re: C bug of the day Date: 16 Jun 2003 05:06:40 -0400 Organization: EarthLink Inc. -- http://www.EarthLink.net Sender: cppmods@netlab.cs.rpi.edu Message-ID: References: Reply-To: jpotter@penguin.lhup.edu NNTP-Posting-Host: netlab.cs.rpi.edu X-Original-Date: Mon, 16 Jun 2003 02:29:21 GMT X-Submission-Address: c++-submit@netlab.cs.rpi.edu X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated iQBVAwUAPu2InUHMCo9UcraBAQH1ZwIAgjna3Ynkt6rdu6PaSV4GM8F5zDG3WCHi J5zWj17EvhkqdmFuUhSv9ppucu1AXnZM64OI2bocjxykUMzUGPaaLA== =5Frt Xref: archiver1.google.com comp.lang.ada:39225 comp.lang.c++.moderated:68450 Date: 2003-06-16T05:06:40-04:00 List-Id: On 15 Jun 2003 17:55:12 -0400, Francis Glassborow wrote: > In message , John Potter > writes > >> int i(read(stream)); > >Let's see your template. My guess: > >template > >T read (istream& is) { > > T item; // uninitialized or default constructed > > is >> item; > > return item; > > } > >I'm guessing that you are just hiding the uninitialized fundamental or > >default constructing a udt. > Come on, I can write better code than that. The main point was that > input should be at least validated as appropriate to the type,. Your article was in the part of the thread talking about uninitialized variables. You claimed that any decent programmer had a way around that. The first line is all that counts and it matches your posted code. The template does not solve the problem no matter how much error testing you add. You still have a desirable uninitialized fundamental and can not avoid default construction of udt. It is possible to avoid the problem for udt with a constructor taking a stream; however, that does not generalize to a universal template. Not a question of the quality of your code. Just a guess that it had nothing to do with the subject. QED. John [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]