a refresher course in
programming in C
and debugging with GDB

Picture of Don Knuth

“...almost everything I’ve ever heard associated with the term ‘extreme programming’ sounds like exactly the wrong way to go...with one exception. The exception is the idea of working in teams and reading each other’s code.” —Don Knuth

git init
git add .
git commit
git branch
git branch experimental
git checkout experimental
# hack hack hack
git diff
git add file.c
git commit
gdb progname
(gdb) run args...
(gdb) break funcname
(gdb) backtrace
(gdb) next
(gdb) continue
(gdb) up # stack frame
(gdb) down # stack frame
(gdb) list lineno
(gdb) print varname
(gdb) p/x varname # print as hex
(gdb) ptype varname # print type
(gdb) x addr # examine memory
(gdb) x/10x addr
(gdb) x/s addr
(gdb) disassemble funcname

Press Enter to repeat the last command.

GCC options

gcc -g -Wall -Werror -o prog prog.c
-g
enable debugging info
-Wall
warn about everything reasonable
-Werror
turn warnings into errors
int a[] = {3, 5, 2, 6, 7};
int i;

for (i = 0; i < sizeof(a)/sizeof(*a); i++) {
	...
}

The C Programming Language, Section 6.3.