6.6.5.1 -g

Produce debugging information.

The compiler supports the use of -g with -O making it possible to debug optimized code. The shortcuts taken by optimized code may occasionally produce surprising results:

  • Some declared variables may not exist at all.
  • Flow of control may briefly move unexpectedly.
  • Some statements may not be executed because they compute constant results or their values were already at hand.
  • Some statements may execute in different places because they were moved out of loops.

    Nevertheless it proves possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might have bugs.