From: Ethan A M. <merritt@u.washington.edu> - 2006-07-08 20:00:01
|
On Saturday 08 July 2006 12:22 pm, Hans-Bernhard Br=F6ker <broeker@physik.r= wth-aachen.de> wrote: >=20 > [gcc -Wuninitialized warnings] >=20 > > I don't know of any way to make gcc more accurate in such cases. >=20 > Well, just initialize them! Worst that can happen is that the code=20 > gratuitously grows by 3 'load value into variable' operations. *If*=20 > they're actually false alarms, that is. Not quite. The worst thing that can happen is that by initializing to some spurious value, you trigger run-time errors that are no longer accompanied by a relevant compiler warning. Hiding a possible problem is worse than leaving the possibly spurious error message. The problematic constuct is code like the following: if (foo) { ... baz =3D something_calculated; } [lots of code] if (foo) { do_something_with(baz); } gcc recognizes that baz is set only inside an if () statement, but fails to notice that it is only dereferenced inside a=20 matching if () statment. Yes, you could initialize at the head of the program: static double baz =3D 0.0; But if somehow the pair of if conditions are not truly equivalent, then you have a problem regardless of the fact that baz has been initialized. It is true that in many cases an incorrect value of 0 is less likely to cause a segfault than an incorrect value of NaN. But it's incorrect either way, and I see no particular virtue in silencing the compiler's attempt to point out the source of a possible problem. =20 =2D-=20 Ethan A Merritt Biomolecular Structure Center University of Washington, Seattle 98195-7742 |