Here are mine:

  • -Wextra and -Wall: essential.
  • -Wfloat-equal: useful because usually testing floating-point numbers for equality is bad.
  • -Wundef: warn if an uninitialized identifier is evaluated in an #if directive.
  • -Wshadow: warn whenever a local variable shadows another local variable, parameter or global variable or whenever a built-in function is shadowed.
  • -Wpointer-arith: warn if anything depends upon the size of a function or of void.
  • -Wcast-align: warn whenever a pointer is cast such that the required alignment of the target is increased. For example, warn if a char * is cast to an int * on machines where integers can only be accessed at two- or four-byte boundaries.
  • -Wstrict-prototypes: warn if a function is declared or defined without specifying the argument types.
  • -Wstrict-overflow=5: warns about cases where the compiler optimizes based on the assumption that signed overflow does not occur. (The value 5 may be too strict, see the manual page.)
  • -Wwrite-strings: give string constants the type const char[length] so that copying the address of one into a non-const char * pointer will get a warning.
  • -Waggregate-return: warn if any functions that return structures or unions are defined or called.
  • -Wcast-qual: warn whenever a pointer is cast to remove a type qualifier from the target type*.
  • -Wswitch-default: warn whenever a switch statement does not have a default case*.
  • -Wswitch-enum: warn whenever a switch statement has an index of enumerated type and lacks a case for one or more of the named codes of that enumeration*.
  • -Wconversion: warn for implicit conversions that may alter a value*.
  • -Wunreachable-code: warn if the compiler detects that code will never be executed*.

Those marked * sometimes give too many spurious warnings, so I use them on as-needed basis.

Answer from Alok Singhal on Stack Overflow
🌐
GNU
gcc.gnu.org › onlinedocs › gcc › Option-Summary.html
Option Summary (Using the GNU Compiler Collection (GCC))
See Options for Code Generation Conventions. -fcall-saved-reg -fcall-used-reg -ffixed-reg -fexceptions -fnon-call-exceptions -fdelete-dead-exceptions -funwind-tables -fasynchronous-unwind-tables -fno-gnu-unique -finhibit-size-directive -fcommon -fno-ident -fpcc-struct-return -fpic -fPIC -fpie -fPIE -fno-plt -fno-jump-tables -fno-bit-tests -frecord-gcc-switches -freg-struct-return -fshort-enums -fshort-wchar -fverbose-asm -fpack-struct[=n] -fleading-underscore -ftls-model=model -fstack-reuse=reuse_level -ftrampolines -ftrampoline-impl=[stack|heap] -ftrapv -fwrapv -fwrapv-pointer -fvisibility=[default|internal|hidden|protected] -fstrict-volatile-bitfields -fsync-libcalls -fzero-init-padding-bits=value -Qy -Qn
🌐
Linux Man Pages
man7.org › linux › man-pages › man1 › gcc.1.html
gcc(1) - Linux manual page
The name of the wrapper program ... list. gcc -c t.c -wrapper gdb,--args This invokes all subprograms of gcc under gdb --args, thus the invocation of cc1 is gdb --args cc1 .... -ffile-prefix-map=old=new When compiling files residing in directory old, record any references to them in the result of the compilation as if the files resided in directory new instead. Specifying this option is equivalent ...
🌐
IBM
ibm.com › docs › en › xl-c-and-cpp-linux › 16.1.0
Supported GCC options
We cannot provide a description for this page right now
🌐
SPEC
spec.org › cpu2017 › flags › gcc.2018-02-16.html
GNU Compiler Collection Flags
On x86 systems, allows use of instructions that require the listed architecture. ... Generate code for processors that include the AVX extensions. ... On SPARC systems, mcpu sets the available instruction set. On x86 systems, mcpu is a deprecated synonym for mtune. ... -mrecip This option enables use of "RCPSS" and "RSQRTSS" instructions (and their vectorized variants "RCPPS" and "RSQRTPS") with an additional Newton-Raphson step to increase precision instead of "DIVSS" and "SQRTSS" (and their vectorized variants) for single-precision floating-point arguments.
🌐
Florida State University
cs.fsu.edu › ~baker › ada › gnat › html › gcc_3.html
3. GCC Command Options
This manual lists only one of the two forms, whichever is not the default. The following options control the amount and kinds of warnings produced by GCC; for further, language-specific options also refer to 3.5 Options Controlling C++ Dialect and 3.6 Options Controlling Objective-C Dialect.
🌐
GNU
gcc.gnu.org › onlinedocs › gcc-3.2.1 › gcc › Invoking-GCC.html
GCC Command Options
See Option Index, for an index to GCC's options. Option Summary: Brief list of all options, without explanations.
Find elsewhere
🌐
RapidTables
rapidtables.com › code › linux › gcc.html
GCC C compiler
gcc options · gcc examples · gcc code generator · $ gcc [options] [source files] [object files] [-o output file] GCC main options: Compile file1.c and file2.c and link to output file execfile: $ gcc file1.c file2.c -o execfile · Run output file execfile: $ ./execfile ·
Top answer
1 of 16
178

Here are mine:

  • -Wextra and -Wall: essential.
  • -Wfloat-equal: useful because usually testing floating-point numbers for equality is bad.
  • -Wundef: warn if an uninitialized identifier is evaluated in an #if directive.
  • -Wshadow: warn whenever a local variable shadows another local variable, parameter or global variable or whenever a built-in function is shadowed.
  • -Wpointer-arith: warn if anything depends upon the size of a function or of void.
  • -Wcast-align: warn whenever a pointer is cast such that the required alignment of the target is increased. For example, warn if a char * is cast to an int * on machines where integers can only be accessed at two- or four-byte boundaries.
  • -Wstrict-prototypes: warn if a function is declared or defined without specifying the argument types.
  • -Wstrict-overflow=5: warns about cases where the compiler optimizes based on the assumption that signed overflow does not occur. (The value 5 may be too strict, see the manual page.)
  • -Wwrite-strings: give string constants the type const char[length] so that copying the address of one into a non-const char * pointer will get a warning.
  • -Waggregate-return: warn if any functions that return structures or unions are defined or called.
  • -Wcast-qual: warn whenever a pointer is cast to remove a type qualifier from the target type*.
  • -Wswitch-default: warn whenever a switch statement does not have a default case*.
  • -Wswitch-enum: warn whenever a switch statement has an index of enumerated type and lacks a case for one or more of the named codes of that enumeration*.
  • -Wconversion: warn for implicit conversions that may alter a value*.
  • -Wunreachable-code: warn if the compiler detects that code will never be executed*.

Those marked * sometimes give too many spurious warnings, so I use them on as-needed basis.

2 of 16
77

Several of the -f code generation options are interesting:

  • -fverbose-asm is useful if you're compiling with -S to examine the assembly output - it adds some informative comments.

  • -finstrument-functions adds code to call user-supplied profiling functions at every function entry and exit point.

  • --coverage instruments the branches and calls in the program and creates a coverage notes file, so that when the program is run coverage data is produced that can be formatted by the gcov program to help analysing test coverage.

  • -fsanitize={address,thread,undefined} enables the AddressSanitizer, ThreadSanitizer and UndefinedBehaviorSanitizer code sanitizers, respectively. These instrument the program to check for various sorts of errors at runtime.

Previously this answer also mentioned -ftrapv, however this functionality has been superseded by -fsanitize=signed-integer-overflow which is one of the sanitizers enabled by -fsanitize=undefined.

🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › gcc-command-in-linux-with-examples
gcc command in Linux with examples - GeeksforGeeks
October 4, 2025 - Example: This will compile the source.c file and give the output file as a.out file which is default name of output file given by gcc compiler, which can be executed using ./a.out ... Most Useful Options with Examples: Here source.c is the C program code file.
🌐
GNU
gcc.gnu.org › onlinedocs › gcc-3.2 › gcc › Invoking-GCC.html
GCC Command Options - GNU
See Option Index, for an index to GCC's options. Option Summary: Brief list of all options, without explanations.
🌐
GNU
gcc.gnu.org › onlinedocs › gcc › x86-Options.html
x86 Options (Using the GNU Compiler Collection (GCC))
This option is used to do fine-grain control of x86 code generation features. feature-list is a comma-separated list of feature names. See also -mdump-tune-features. When specified, the feature is turned on if it is not preceded with ‘^’; otherwise, it is turned off.
🌐
The Geek Stuff
thegeekstuff.com › 2012 › 10 › gcc-compiler-options
15 Most Frequently Used GCC Compiler Command Line Options
October 30, 2012 - COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper Target: i686-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --e
🌐
GNU
gcc.gnu.org › onlinedocs › gcc-3.3 › gcc › Option-Summary.html
Option Summary - GCC, the GNU Compiler Collection
-all_load -allowable_client -arch -arch_errors_fatal -arch_only -bind_at_load -bundle -bundle_loader -client_name -compatibility_version -current_version -dependency-file -dylib_file -dylinker_install_name -dynamic -dynamiclib -exported_symbols_list -filelist -flat_namespace -force_cpusubtype_ALL -force_flat_namespace -headerpad_max_install_names -image_base -init -install_name -keep_private_externs -multi_module -multiply_defined -multiply_defined_unused -noall_load -nomultidefs -noprebind -noseglinkedit -pagezero_size -prebind -prebind_all_twolevel_modules -private_bundle -read_only_relocs -
🌐
GNU
gcc.gnu.org › onlinedocs › gcc › Directory-Options.html
Directory Options (Using the GNU Compiler Collection (GCC))
Do not search for header files in the C++-specific standard directories, but do still search the other standard directories. (This option is used when building the C++ library.) ... Append dir directory to the list of searched directories for #embed preprocessing directive or __has_embed macro.
🌐
UC3M
it.uc3m.es › pbasanta › asng › course_notes › compiler_en.html
Chapter 14. The most used options of the gcc compiler
The GNU C compiler gcc is the application that given a set of files with C code, generates an executable program. As with the rest of applications, it can be invoked from the command interpreter. With the option --version the compiler only shows information about its version.
🌐
Medium
medium.com › @eightlimbed › commonly-used-gcc-options-explained-8304dfccea20
Commonly Used GCC Options Explained | by Lee Gaines | Medium
December 19, 2019 - Werror — This option turns any warning into an error. Usually warnings are just that: they warn you of potential problems, but they still allow GCC to compile your program.
🌐
Stanford
web.stanford.edu › class › archive › cs › cs107 › cs107.1186 › unixref › topics › gcc
gcc (how to compile c programs)
We generally don't want our programs named a.out, so you can give gcc an option, -o programName, to tell it what to name the runnable file:
🌐
Red Hat
developers.redhat.com › blog › 2018 › 03 › 21 › compiler-and-linker-flags-gcc
Recommended compiler and linker flags for GCC | Red Hat Developer
July 2, 2024 - Be aware that -O3 will change the way code reacts to ELF symbol interposition, so this option is not entirely ABI-compatible. Overall, we still consider -O2 the choice for the default. -mstackrealign may be needed for compatibility with legacy applications (particularly on i686) which does not preserve stack alignment before calling library functions compiled with recent GCC versions. Some flags are used fairly often, but cause problems. Here is a list of a few of those:
🌐
Linux Man Pages
linux.die.net › man › 1 › gcc
gcc(1): GNU project C/C++ compiler - Linux man page
g++ -g -frepo -O -c firstClass.CIn this example, only -frepo is an option meant only for C ++ programs; you can use the other options with any language supported by GCC . Here is a list of options that are only for compiling C ++ programs: