i
for indices, w
for width, cv
for canvas...). Macros are always uppercase, variable and function names are always lowercase. Use the underscore to separate words within names:
#define BROKEN 0 #define MAX(x, y) ((x > y) ? (x) : (y)) unsigned int x, y, w, h; char *font_name; void frobulate_every_three_seconds(void);
const
is a suffix. It's char
const
*foo
, not const
char
*foo
.
Use spaces after commas and between operators. Do not use spaces after an opening parenthesis or before a closing one:
a += 2; b = (a * (c + d)); x = min(x1, x2, x3);
Do not put a space between functions and the corresponding opening parenthesis:
int function(int); if(a == b) return;
Do not put parentheses around return values:
return a + (b & x) + d[10];
Opening braces should be on a line of their own, aligned with the current block. Braces are optional for one-liners:
int function(int a) { if(a & 0x84) return a; if(a < 0) { return -a; } else { a /= 2; switch(a) { case 0: case 1: return -1; break; default: return a; } } }