Subject: Detecting unintialized variables
To: None <tech-kern@NetBSD.ORG>
From: David Seifert <email@example.com>
Date: 03/29/1996 15:05:00
In message <199603292006.MAA22386@netcom23.netcom.com>you write:
> > > -Wuninitialized is a good warning, but since it's not 100%, I don't
> > > recommend combining it with -Werror. Some people get around this by
> > > always initializing the variable to some dummy value. I think this
> > > is terrible practice, as it defeats the ability of run-time tools
> > > that track variable usage to detect uninitialized variable usage.
> > Well, isn't the point to avoid uninitialized variables?
> > If you initialize it, haven't you solved the problem?
> I don't think so. When a program "acts" on an unintialized variable,
> most often it's a case that the programmer didn't anticipate (ie. a
> bug). If a the variable is initialized "just to shut the compiler
> up", there is no telling that the program will behave as intended when
> that dummy value is acted upon either.
It depends. If there is a safe value that you can initialize it
to, you're okay.
If there isn't a safe value to initialize it to at compile time,
perhaps add a comment /* Complaint from gcc about variable <foo>
uninitialized is okay, as of <date>. <name> */
When someone modifies the code, they should verify that it
is still okay, and update the comment. (Not a wonderful
solution, I know.)
The real solution is to figure out a way to make gcc smarter.