Skip to content

Instantly share code, notes, and snippets.

@shikaan
Created April 1, 2025 16:09
Show Gist options
  • Save shikaan/bb71720d0751b4ea27544f1e31bd86d2 to your computer and use it in GitHub Desktop.
Save shikaan/bb71720d0751b4ea27544f1e31bd86d2 to your computer and use it in GitHub Desktop.
C project boilerplate
CompileFlags:
CompilationDatabase: compile_commands.json
Add: [-x, c, -std=c23]
Diagnostics:
ClangTidy:
Add: [modernize-*, bugprone-*, llvm-*, performance-*, readability-*]
CheckOptions:
readability-identifier-naming.ConstantCase: UPPER_CASE
readability-identifier-naming.ConstexprVariableCase: UPPER_CASE
readability-identifier-naming.EnumConstantCase: UPPER_CASE
readability-identifier-naming.GlobalConstantCase: UPPER_CASE
readability-identifier-naming.StaticConstantCase: UPPER_CASE
readability-identifier-naming.LocalVariableCase: lower_case
readability-identifier-naming.EnumCase: lower_case
readability-identifier-naming.StructCase: lower_case
readability-identifier-naming.TypeAliasCase: lower_case
readability-identifier-naming.TypeAliasSuffix: _t
readability-identifier-naming.TypedefCase: lower_case
readability-identifier-naming.TypedefSuffix: _t
readability-identifier-naming.FunctionCase: camelBack
readability-identifier-naming.GlobalFunctionCase: camelBack
readability-braces-around-statements.ShortStatementLines: 2
UnusedIncludes: Strict
.POSIX:
CC := clang
CFLAGS :=-std=c23 \
-O2 \
-Wall \
-Wformat \
-Wformat=all \
-Wconversion \
-Werror=format-security \
-Werror=implicit \
-Werror=incompatible-pointer-types \
-Werror=int-conversion \
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 \
-D_GLIBCXX_ASSERTIONS \
-fstrict-flex-arrays=3 \
-fstack-clash-protection -fstack-protector-strong \
-Wl,-z,nodlopen -Wl,-z,noexecstack \
-Wl,-z,relro -Wl,-z,now \
-Wl,--as-needed -Wl,--no-copy-dt-needed-entries \
-fno-delete-null-pointer-checks \
-fno-strict-overflow \
-fno-strict-aliasing \
-ftrivial-auto-var-init=zero \
# if executable -fPIE -pie \
# if shared lib -fPIC -shared \
# if x86_64 -fcf-protection=full \
# if aarch64 -mbranch-protection=standard \
-Wextra \
-fno-common \
-Winit-self \
-Wfloat-equal \
-Wundef \
-Wshadow \
-Wpointer-arith \
-Wcast-align \
-Wstrict-prototypes \
-Wstrict-overflow=5 \
-Wwrite-strings \
-Waggregate-return \
-Wcast-qual \
-Wswitch-default \
-Wswitch-enum \
-Wassign-enum \
-Wimplicit-fallthrough \
-Wno-ignored-qualifiers \
-Wno-aggregate-return
DEBUG_FLAGS:=-Werror -g -fdiagnostics-color=always -fsanitize=address,undefined
all: #dependencies
# debug: CFLAGS += $(DEBUG_FLAGS)
# debug: all
.PHONY: configure
configure:
bear -- make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment