Re: Initialising Variables
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Thu, 25 Jan 2007 02:51:36 +0000
Keith Thompson said:
<snip>
Yes, but a default value (unless you can choose one that's guaranteed
to be invalid) can also mask a bug.
How so? Surely it will lead to incorrect results?
Suppose you initialize a variable with some default value, you intend
to compute a new value for it, but you fail to do so (that's the bug.
If the default value allows the code to execute but produce quietly
incorrect results, it's going to be difficult to track down the
problem.
I disagree. Your clue is that the results are incorrect. From there, it's
just a matter of finding out why. In my experience, this is a lot easier
when the results are reproducible.
If you had left off the initialization, your compiler
*might* have been able to warn you that you're using a possibly
uninitialized variable, or the random garbage in the variable *might*
have caused a more drastic failure during testing
Yes, but I see a lot of "might"s in there. If you could guarantee this
behaviour, I'd be a lot happier.
(as opposed to a
subtle failure that's still there in the shipped product).
If so, then that's a failure of one's testing process, since one's testers
clearly assume that any run not resulting in a crash is a successful run.
Well, testers, here's your final production code:
int main(void) { return 0; }
It doesn't crash. Hey, it must be right!
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.
- Follow-Ups:
- Re: Initialising Variables
- From: Mark McIntyre
- Re: Initialising Variables
- From: Keith Thompson
- Re: Initialising Variables
- References:
- Initialising Variables
- From: DaveC
- Re: Initialising Variables
- From: santosh
- Re: Initialising Variables
- From: Richard Heathfield
- Re: Initialising Variables
- From: santosh
- Re: Initialising Variables
- From: Keith Thompson
- Initialising Variables
- Prev by Date: Re: what is 0xFFFFFFF ?
- Next by Date: Re: The clc wiki
- Previous by thread: Re: Initialising Variables
- Next by thread: Re: Initialising Variables
- Index(es):
Relevant Pages
|
|