There isn't an easy way to spot the options used by the compiler. All else apart, most programs are built from many source files, and those source files may have been compiled with different sets of options.
Usually, if you want to know, you control it with a command-line #define
:
gcc -DMODE=MODE_OPTIM -O3 …
gcc -DMODE=MODE_DEBUG -ggdb3 …
where you have a header that defines the meaning of MODE_OPTIM
and MODE_DEBUG
:
enum CompilationMode { MODE_OPTIM, MODE_DEBUG };
#ifndef MODE
#define MODE MODE_DEBUG
#endif
extern enum CompilationMode compiled_for;
And somewhere you define that:
enum CompilationMode compiled_for = MODE;
And then you can test compiled_for
wherever you need to know which mode the program was built with.
Actually, this is runtime decision making. For compile time decision making, you replace the enum
with:
#define MODE_OPTIM 0
#define MODE_DEBUG 1
and you can test:
#if MODE == MODE_DEBUG
do_some_function();
#else
do_another_function();
#endif