Cheat sheets

PCC-02Cheat sheet1 pageIn a paid pack

Types, Sizes, Limits and Literals

What the C standard fixes about object sizes and what it leaves to the implementation, the ILP32, LLP64 and LP64 data models, ranges of n-bit signed and unsigned integers, the type of an integer constant (decimal versus octal and hexadecimal, suffixes), character constants and escapes, octal traps, why there are no negative literals, sizeof as an unevaluated operator, and floating-point precision traps. Every value is compiled with gcc or computed by a script.

PCC-03Cheat sheet1 pageIn a paid pack

Integer Promotions and Arithmetic Conversions

The integer promotions, conversion rank, the usual arithmetic conversions applied per operator, signed and unsigned comparison pitfalls (-1 < 1u, sizeof and strlen differences), why -1L < 1u depends on the data model, integer division before floating conversion, truncation of floating values, and what happens when a value is converted to a narrower signed, unsigned or _Bool type.

PCC-04Cheat sheet1 pageIn a paid pack

Operators, Precedence and Associativity

The full C precedence and associativity ladder, integer division and remainder with negative operands, assignment and compound assignment values, the comma operator, the conditional operator and its result type, relational chains, logical results, maximal munch in tokens such as x+++y, and the lvalue rules that make some expressions fail to compile. All values are compiled with gcc.

PCC-05Cheat sheet1 pageIn a paid pack

Bitwise Operators, Shifts and Bit Tricks

The bitwise operators on promoted operands, masks to set, clear, toggle and test bit k, left and right shifts as multiplication and division for unsigned values, implementation-defined right shift of negative values, the shift cases that are undefined, the lowest-set-bit tricks with x & (x - 1) and x & -x, counting 1 bits, the XOR swap and its aliasing trap, and complementing small unsigned types.

PCC-19Cheat sheet1 pageIn a paid pack

Preprocessor, Macros and Formatted I/O

Macro expansion as token substitution before compilation, missing parentheses, arguments with side effects evaluated twice, multi-statement macros and do-while(0), stringising and token pasting, conditional compilation and include guards, typedef versus #define for pointer types, printf conversion specifiers, widths and precisions, printf's return value, scanf's return value and leftover input, and getchar with EOF.