Math-Linux.com

Knowledge base dedicated to Linux and applied mathematics.

Home > C++ > FAQ C++ > FAQ C++ - gcc/g++ > gcc /g++ Why some variables are not detected as not used during compilation?

gcc /g++ Why some variables are not detected as not used during compilation?

In the following example, variable x is not detected as not used


#include <vector>

int main()
{
	std::vector< double > x;
	int k,l;
}

g++ -Wall test.cpp
test.cpp: In function 'int main()':
test.cpp:6:6: warning: unused variable 'k'
test.cpp:6:8: warning: unused variable 'l'

Actually, warnings are only declared for built in types (bool, int, float, double, etc ...). Compiler can’t determine if removing declaration of x would change the behaviour of semantics program.

Also in this section

  1. Build in release mode with full optimizations in gcc / g++
  2. Code that compiles with gcc but not g++
  3. Disable all gcc / g++ warnings
  4. g++ compilation option -Weffc++
  5. gcc / g++ find where a header file is included from
  6. gcc / g++ how to dump all preprocessor definitions
  7. gcc / g++ preprocessor flags for the compiler version number
  8. gcc /g++ Why some variables are not detected as not used during compilation?
  9. Undefined Symbol ___gxx_personality_v0