From -7037353452890877972
X-Google-Thread: f78e5,e2cfdf64f67c7793
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 28 Sep 2004 14:00:05 -0500
Return-Path: <devnull@Algebra.Com>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Date: Tue, 28 Sep 2004 18:56:07 GMT
Delivered-To: std-c++@ucar.edu
From: brangdon@cix.co.uk (Dave Harris)
Newsgroups: comp.std.c++
Subject: Re: Eliminating uninitialised variables
Message-ID: <memo.20040928170100.2848A@brangdon.m>
References: <41573b0a$0$29917$cc9e4d1f@news.dial.pipex.com>
Reply-To: brangdon@cix.co.uk
X-Orig-X-Trace: news.uni-berlin.de eGNygg8Ork+nDbFF3UjzBQk2g/5B3Sj6tjwXczSeorBLNLu/0=
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
X-Spam-Checker-Version: SpamAssassin 2.64 (2004-01-11) on manifold.algebra.com
X-Spam-Status: No, hits=0.0 required=3.0 tests=none autolearn=no version=2.64
Lines: 40
NNTP-Posting-Host: 64.81.147.48
X-Trace: sv3-FAvUDjlHhz+xRfiSr8y6xy/NcCO+1j6cGyl0R5ApEAuDdysBfwwOyvXjAE0BS2QRsBJ/oquFozBGjA2!gsIU5iVYr0DGcOQdh+Pc0MvMKPHGu5Nk9k9tRaTFEigQkIQItQHJ+cOGh0vhhcBQnH6WlJ8Z49Ed!UuAEmPOwz9BJpUAJaQ==
X-Complaints-To: abuse@speakeasy.net
X-DMCA-Complaints-To: abuse@speakeasy.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.16
Xref: g2news1.google.com comp.std.c++:2901

sjhoweATdialDOTpipexDOTcom@eu.uu.net (Stephen Howe) wrote (abridged):
> And does zero-initialising mean that the program is correct or will 
> behave more correctly?

In many cases, yes. It at least makes the behaviour consistent, so that 
the problem is easier to track down.


> I have to say in the past 5 years, I have not been bitten once by 
> "uninitialised variables".
> It is not a signicant problem to me.

Data point noted. I'm guessing you're a relatively experienced programmer?

I've been bitten by it, mainly in code written by other people. In 
particular with IEEE doubles, which sometimes became signalling NaNs in 
release mode. As I recall, the code which read them was a 
copy-constructor. It didn't matter what their value was so long as they 
could be read without the access throwing an exception, so in this case 
zero-initialisation would have been fine. Whether they threw depended on 
the history of the heap, so it was quite hard to debug. I was using a 
compiler which initialises heap to a known state in debug releases, which 
masked the problem further.


> I don't see that this gains anything.

I hope I have now convinced you otherwise. In my view, eliminating 
potential undefined behaviour always has some benefit; the question is 
whether the benefit is worth the cost. And in this case I think the cost 
can be made small.

-- Dave Harris, Nottingham, UK

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



