A small list of GCC Hacks

  1. g++ -o helloworld helloworld.cc produces helloworld binary from helloworld.cc C++ file.

  2. use -Wall switch turns on all warnings(potential errors) in the code (like unused variables)

  3. g++ -E helloworld.cc generates output code after the pre-processing stage.

  4. use -O1 switch for level 1 optimization and -O3 for level 3 optimization (very rigorous)

  5. use -Os switch for generating code which is small in size

  6. g++ -S helloworld.cc generates asm code helloworld.S

  7. g++ -DNAME=“ashish” helloworld.cc equivalent to writing #define NAME ashish in the code.

  8. cpp -dM /dev/null lists all gcc macros available on the system as a part of GCC standard (they all starts with two underscores)

Reference

  1. GCC man page
  2. CPP man page