This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
-Wuninitialized not so hot.
- To: <gcc-bugs at gcc dot gnu dot org>
- Subject: -Wuninitialized not so hot.
- From: Trent Waddington <trentw at vmware dot com>
- Date: Wed, 13 Jun 2001 18:55:34 -0700 (PDT)
The warning option -Wuninitialized does not result in a warning message if
the address of a possibily uninitialized variable is taken, even if
after the first use. This actually occured and was a source of
frustration. For example the following program:
#include <stdio.h>
int checkit(int i) {
return i % 16;
}
void modit(int *i) {
*i = 5;
}
int main(int argc, char * argv[])
{
int noinithere;
if (checkit(noinithere)) {
printf("terribly bad situation\n");
return 1;
}
modit(&noinithere);
return 0;
}
Compiling this program using options -Wuninitialized -O results in no
warnings. However, commenting out the call to modit gives the correct
warning. In other news, I'm informed a complete lack of warning for this
program:
int main(int argc, char * argv[])
{
int foo = foo;
}
also wasted a few hours of debugging.
Trent Waddington
VMWare Code Monkey.