Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 1st, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why does g   warning about uninitialized variable depend on the type of the variable? (it warns for an int but not for a double)
  2. #include <iostream>
  3.  
  4. typedef double barType;
  5.  
  6. struct foo {
  7.  
  8.     barType bar;
  9.  
  10. };
  11.  
  12. int main() {
  13.  
  14.     foo f;
  15.  
  16.     std::cout << f.bar << std::endl;
  17.  
  18. }
  19.        
  20. $ g++ -O1 -Wall test.cc -o test
  21.        
  22. $ g++ -O1 -Wall test.cc -o test
  23.   test.cc: In function ‘int main()’:
  24.   test.cc:17: warning: ‘f.foo::bar’ is used uninitialized in this function
  25.        
  26. $ g++ --version
  27. g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1
  28. Copyright (C) 2009 Free Software Foundation, Inc.
  29. This is free software; see the source for copying conditions.  There is NO
  30. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  31.        
  32. cc1plus: warning: -Wuninitialized is not supported without -O