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
🌐
Pandoc
pandoc.org › installing.html
Pandoc - Installing pandoc
pandoc’s flags include: embed_data_files: embed all data files into the binary (default no). This is helpful if you want to create a relocatable binary. ... server: compile in support for running in HTTP server mode when the executable is renamed (or symlinked as) pandoc-server.
🌐
Nullprogram
nullprogram.com › blog › 2023 › 04 › 29
My favorite C compiler flags during development
April 29, 2023 - Also, when compiling you can combine sanitizers like so: ... As of this writing, MSVC does not have UBSan, but it does have a similar feature, run-time error checks. Three sub-flags (c, s, u) enable different checks, and /RTCcsu turns them all on. The c flag generates the assertion I had manually ...
Discussions

[u/skeeto's blog] "My favorite C compiler flags during development"
UBSan and ASan have been a tremendous help, and in my time on reddit I don't think I've personally seen anybody mention them except skeeto, who rightfully mentions them a lot. My software rasterizer was riddled with memory issues and undefined behavior that I thought I had been clever enough to avoid, and without these dynamic check tools I shudder to think of all the crashes and weird quirks in my program that I'd still just be guessing about. More on reddit.com
🌐 r/C_Programming
13
137
April 30, 2023
What are the useful GCC flags for C? - Stack Overflow
Beyond setting -Wall, and setting -std=XXX, what other really useful, but less known compiler flags are there for use in C? I'm particularly interested in any additional warnings, and/or and turning More on stackoverflow.com
🌐 stackoverflow.com
C programming's -O3 equivalent compiler flag in rust
https://doc.rust-lang.org/stable/rustc/codegen-options/index.html#opt-level If you’re using Cargo, I believe —release passes -C opt-level=3 Yeah it is: https://doc.rust-lang.org/cargo/reference/profiles.html#release More on reddit.com
🌐 r/rust
14
9
May 15, 2020
How do I add compiler flags to clangd LSP configuration?
local lspconfig = require("lspconfig") lspconfig.clangd.setup( { cmd = { "clangd", "--background-index", "--suggest-missing-includes", "--clang-tidy", "-Wall", "--header-insertion=iwyu" }, on_init = custom_init, on_attach = custom_attach, } } My guess it would be like this, but test it and let me know More on reddit.com
🌐 r/neovim
17
4
January 10, 2021
🌐
Cam
wikis.ch.cam.ac.uk › ro-walesdocs › wiki › index.php › Compiler_Flags
Compiler Flags - Docswiki
-ftrapv The compiler creates a runtime trap when a variable overflow occurs. -fimplicit-none No implicit typing is allowed, unless there is an explicit IMPLICIT statement. This is equivalent to putting IMPLICIT NONE everywhere there isn't already an IMPLICIT statement. All: -Mextend -mcmodel=medium (only for NEWREAXFFOPTIM) ... -mcmodel=medium This is only when building with NEWREAXFFOPTIM. The flag must be used to compile/link a program whose data and .bss sections exceed 2GB.
🌐
Reddit
reddit.com › r/c_programming › [u/skeeto's blog] "my favorite c compiler flags during development"
r/C_Programming on Reddit: [u/skeeto's blog] "My favorite C compiler flags during development"
April 30, 2023 - Right before this I was reading JeanHeyd’s blog about C23 enums and changed my build settings to remove short-enums because I thought the compiler would optimize the type of the enum with that flag, but what it actually does is change all enums type from signed int to signed short, I’ve ...
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.

🌐
Oracle
docs.oracle.com › cd › E19957-01 › 806-3567 › cc_options.html
cc Compiler Options
Retains temporary files created during compilation instead of deleting them automatically. ... dir to the list of directories searched for libraries by ld(1). This option and its arguments are passed to ld. ... name.a. The order of libraries in the command-line is important, as symbols are resolved from left to right. ... Removes duplicate strings from the .comment section of the object file. When you use the -mc flag, mcs -c is invoked.
Find elsewhere
🌐
SPEC
spec.org › cpu2017 › flags › gcc.2018-02-16.html
GNU Compiler Collection Flags
Tells GCC to use the GNU semantics for "inline" functions, that is, the behavior prior to the C99 standard. This switch may resolve duplicate symbol errors, as noted in the 502.gcc_r benchmark description. ... Enabled: Put all local arrays, even those of unknown size onto stack memory. The -fno- form disables the behavior. ... The language standards set aliasing requirements: programmers are expected to follow conventions so that the compiler can keep track of memory.
🌐
Rocket Software
docs.rocketsoftware.com › bundle › cobolit_compiler_suite_runtime_rg_412 › page › cobc-compiler-f-flags.html
Compiler -f Flags
July 3, 2025 - Skip to main contentSkip to search · Powered by Zoomin Software. For more details please contactZoomin · Log in to get a better experience · Login · Rocket Software · 77 4th Avenue Waltham, MA 02451 USA · Products · About · Contact · Resources
🌐
IBM
ibm.com › docs › en › xl-c-and-cpp-aix › 16.1.0
XL C/C++ for AIX
We cannot provide a description for this page right now
🌐
Bookmarklet Maker
caiorss.github.io › C-Cpp-Notes › compiler-flags-options.html
CPP/C++ Compiler Flags and Options
June 4, 2021 - => Add search path to shared libraries, directory containing *.so, *.dll or *.dlyb files such as libLinearAlgebra.so depending on the current operating system. ... Add search path to header files (.h) or (.hpp). ... Turns on lots of compiler warning flags, specifically (-Waddress, -Wcomment, -Wformat, -Wbool-compare, -Wuninitialized, -Wunknown-pragmas, -Wunused-value, -Wunused-value …)
🌐
SourceForge
sourceforge.net › projects › orwelldevcpp
Dev-C++ download | SourceForge.net
1 week ago - I find it a great tool for learning to program in C and C++! I have been using it as my main IDE for several years! Too bad I have never found a user's manual that reveals all its secrets. But I decided to fill this gap by writing my own guide. Stay tuned! UPDATE August 18, 2023: For people who read Italian, I have started writing a guide to using Dev-C++ 5.11 (Orwell version).
Rating: 4.5 ​ - ​ 141 votes
🌐
PlatformIO
platformio.org
Your Gateway to Embedded Software Development Excellence · PlatformIO
Unlock the true potential of embedded software development with PlatformIO's collaborative ecosystem, embracing declarative principles, test-driven methodologies, and modern toolchains for unrivaled success.
🌐
RegExr
regexr.com
RegExr: Learn, Build, & Test RegEx
Flags · Add Test · No match. Add Test · Build a suite of tests that your expression should (or should not) match. Create new tests with the 'Add Test' button. Click a test to edit the name, type, & text. Sign in to persist favorites & patterns. Click the help icon above for info.
🌐
Wikipedia
en.wikipedia.org › wiki › Bit_field
Bit field - Wikipedia
2 days ago - Writing, reading or toggling bits in flags can be done only using the OR, AND and NOT operations – operations which can be performed quickly in the processor. To set a bit, OR the status byte with a mask byte.
🌐
Bun
bun.com
Bun — A fast all-in-one JavaScript runtime
Bun.Archive API for creating & extracting tarballs with gzip compression, Bun.JSONC for parsing JSON with comments, metafile & files options in ... ... Bun.Terminal API, compile-time feature flags, improved Bun.stringWidth accuracy, V8 C++ value type checking APIs, Content-Disposition support fo...
🌐
LabEx
labex.io › tutorials › cpp-how-to-select-correct-c-compiler-flag-464432
How to select correct C++ compiler flag | LabEx
They allow developers to customize how source code is compiled, optimized, and processed. Compiler flags can be categorized into several main types:
🌐
ReqBin
reqbin.com › curl
Run Curl Commands Online
Run, save, and collaborate Curl commands directly from your browser. Test APIs, websites, and web services and validate server responses without installing additional software or plugins. Learn Curl with an extensive database of handpicked Curl examples. See why 850,000 users use ReqBin online ...