Skip to content

Instantly share code, notes, and snippets.

@chiefnoah
Created July 3, 2023 15:25
Show Gist options
  • Save chiefnoah/eea08c8aaaee7d922259a11a8efedbac to your computer and use it in GitHub Desktop.
Save chiefnoah/eea08c8aaaee7d922259a11a8efedbac to your computer and use it in GitHub Desktop.
C Flags
  • Good C Compiler Flags
    • Source
    • -Wall -Wextra
      • Static warnings
    • Dynamic Runtime Checks
      • export ASAN_OPTIONS=abort_on_error=1:halt_on_error=1
        export UBSAN_OPTIONS=abort_on_error=1:halt_on_error=1
        
      • -fsanitize=address
        • Dynamic runtime checks: address sanitizer
      • -fsanitize=undefined
        • Dynamic runtime checks: undefined behavior sanitizer
        • Emits runtime error if UB occurs
      • Combine with -fsanitize=address,undefined
    • Debugging
      • -g3 (don't use plain -g)
    • Warn about stack allocated VLA
      • -Wvla
    • Prevent large stack frames
      • -Wframe-larger-than=5000 -Wstack-usage=10000
    • Prevent Shadowed variables
      • -Wshadow
    • Turn warnings into errors
      • -Werror
    • Keep frame pointers, they're apparently better than DWARF
      • -fno-omit-frame-pointer
    • When building libraries, make sure all symbols between compilations are not exported (private stuff)
      • -fvisibility=hidden
    • Allow signed ints to overflow as expected
      • -fno-strict-overflow -Wno-strict-overflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment