September 2008
Intermediate to advanced
280 pages
6h 31m
English
This has been a lot of information, so a short example of setting breakpoints that you can follow along with is warranted. Consider the following multi-file C code:
main.c
#include <stdio.h>
void swap(int *a, int *b);
int main(void)
{
int i = 3;
int j = 5;
printf("i: %d, j: %d\n", i, j);
swap(&i, &j);
printf("i: %d, j: %d\n", i, j);
return 0;
}
swapper.c
void swap(int *a, int *b)
{
int c = *a;
*a = *b;
*b = c;
}
Compile this code and run GDB on the executable:
$ gcc -g3 -Wall -Wextra -c main.c swapper.c $ gcc -o swap main.o swapper.o $ gdb swap
This is the first time in this book that we've compiled a multi-file C program, so a word is in order. The first line of the compilation process (above) produces two ...