Site icon ashishb.net

GCC Hacks

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.

  1. use -O1 switch for level 1 optimization and -O3 for level 3 optimization (very rigorous)
  2. use -Os switch for generating code which is small in size
  3. g++ -S helloworld.cc generates asm code helloworld.S
  4. g++ -DNAME=”ashish” helloworld.cc equivalent to writing #define NAME ashish in the code.
  5. 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
Exit mobile version