C cheatsheet

GCC flags

1
2
3
4
5
-Wall -Wextra -Wconversion -Werror
-Wpedantic -pedantic-errors ???
-Wno-sign-conversion -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter
-std=c99
-O0 -g

Restrict

Utils

1
2
3
4
5
6
7
8
// stringify a C expression
#define TO_STR(expr) #expr

// ceil(a / b)
#define DIV_CEIL(a, b) (((a) + (b)-1) / (b))

// align an address to a power of 2
#define ALIGN(p, a)  (((u64)(p) + (a)-1) & ~((a)-1))