wg-best-practices-os-developers icon indicating copy to clipboard operation
wg-best-practices-os-developers copied to clipboard

Review "C style" ideas from mcinglis

Open david-a-wheeler opened this issue 9 months ago • 3 comments

"C style" by mcinglis lists some compiler options that might be of use in the C/C++ compiler options guide. These focus on general efforts to find bugs & clean up the code for clarity. Specifically:

  • -Wpedantic
  • -Wno-unused-parameter
  • -Wshadow
  • -Wwrite-strings
  • -Wstrict-prototypes
  • -Wold-style-definition
  • -Wredundant-decls
  • -Wnested-externs
  • -Wmissing-include-dirs

And some GCC-specific ones:

  • -Wjump-misses-init
  • -Wlogical-op

It might also be useful to discuss how to add compiler flags in common cases, e.g., GNU make . You generally want to append not replace the flags. It's generally CFLAGS / CPPFLAGS (C / C++):

CFLAGS += ...
# GCC warnings that Clang doesn't provide:
ifeq ($(CC),gcc)
    CFLAGS += -Wjump-misses-init -Wlogical-op
endif

Automake supports some additional flag variables if you want them to apply in only some cases.

david-a-wheeler avatar May 20 '24 15:05 david-a-wheeler