Usefull GCC compilation flags


Having the -Wall flag enabled by default can potentially save lots of time and headaches when programming in C/C++. Same other usefull flags are :

  • -Wduplicated-cond : Warn about duplicated condition in if-else-if chains.
  • -Wduplicated-branches : Warn when an if-else has identical branches.
  • -Wlogical-op : Warn about use of logical operations where a bitwise operation probably was intended.
  • -Wnull-dereference: Warn when the compiler detects paths that dereferences a null pointer.
  • -Wjump-misses-init: Warn if a goto statement or a switch statement jumps forward across the initialization of a variable, or jumps backward to a label after the variable has been initialized.

source