gccg++

What are useful options for gcc/g++?


It is almost common knowledge that one should always compile with -Wall.

What other useful options are you using when compiling with gcc/g++?


Solution

  • You may want -Wextra in addition of -Wall.

    When debugging your program, -g is needed by gdb.

    and GCC accepts both -g and -O if you really want

    At last, recent versions of GCC (i.e. 4.6 or the 4.7 snapshot) gives better warnings than older ones.

    You could use -pedantic and restrict yourself to some standard, avoiding GNU extensions. I love GNU extensions so I don't want to avoid them.

    So I use -std=gnu99 for C code, and -std=gnu0x or -std=gnu11 for C++11 code because I like extensions.

    And you might consider using or even developing a GCC plugin or a MELT extension for your own specific needs.