Why functions matter
2 min readSo far your programs have been a single main that runs top to bottom. That works for ten lines. It collapses at a thousand lines, and almost every real C program is far larger than that, the Linux kernel alone is millions of lines across thousands of files. The answer is to break a program into small, named pieces and have them call one another.
A function earns its keep in four ways. First, it gives a chunk of work a name, so main can read as a short list of intentions rather than a wall of detail. Second, it removes repetition: a calculation written once inside a function is called from many places instead of copied, and a fix applies everywhere at once. Third, it hides the steps behind an interface, so a caller relies on what a function does, not how it does it. Fourth, it makes the code testable, because you can exercise one function in isolation and check its result directly.
There is no performance reason to avoid small functions. The compiler does not mind how many you write, and modern compilers will inline small functions automatically when it helps. The cost is in your head, not the machine: a clear function is a small thing you can hold in memory and trust.
Function definition, prototype and call
4 min readStart with a function that adds one to an integer:
int plus_one(int n)
{
return n + 1;
}
The int before the name is the return type, the type of the value the function hands back to its caller, written before the function name. plus_one is the name, and int n declares a a local variable named in a function's parameter list that receives a copy of one argument at a call of type int. The body runs return n + 1;, and the return statement computes a value, hands it back to the caller and ends the function.
A function can also return nothing, which is what the keyword void means in the return position:
void hello(void)
{
printf("Hello, world!\n");
}
void in the parameter list means the function takes no arguments, and void as the return type means it returns no value. A void function ends when it reaches the closing brace, or early with a bare return;.
Now the subtle part: the compiler reads a file top to bottom. If main calls plus_one before the compiler has seen plus_one, it does not know what the call should look like. The fix is a a declaration of a function's return type, name and parameter types without its body, used to let callers be checked before the definition appears, also called a declaration. A prototype is the function heading followed by a semicolon:
int plus_one(int n); /* prototype: the signature, no body */
int main(void)
{
int j = plus_one(10);
printf("10 + 1 is %d\n", j);
return 0;
}
int plus_one(int n) /* definition: the body */
{
return n + 1;
}
The prototype lets the compiler check that each argument, the expression written at a call site whose value is copied into the corresponding parameter, has the right type before the definition is ever seen. This matters for the standard functions too: the prototype for printf is not magic, it is typed inside the header stdio.h, which is why you include it.
main is itself a function, one the startup code calls first. It returns an int, and the convention is that 0 means success while a non-zero value reports failure to whoever started the program. The two portable names are EXIT_SUCCESS and EXIT_FAILURE from stdlib.h.
Going deeperThe history: K&R C, ANSI C and the prototype
Early C, the version described in Kernighan and Ritchie's 1978 book, had no prototypes. A function was declared with an empty parameter list such as int plus_one();, and the compiler did no checking of argument types at the call. This is the K&R style, and it survived as a compatibility mode for years. The ANSI C standard of 1989 introduced full prototypes with typed parameter lists and made implicit declaration, calling a function that had never been declared, invalid. It was still tolerated by compilers for decades for old code, which is why you still see warnings about it. Modern C removes it entirely, so a call to an undeclared function is an error, and every function you write in this program is declared before use, normally through a header.
learner@embeddex:~/lab$ # the prototype, the call in main, and the definition below
learner@embeddex:~/lab$ cat plus.c
#include <stdio.h>
int plus_one(int n);
int main(void)
{
int j = plus_one(10);
printf("10 + 1 is %d\n", j);
return 0;
}
int plus_one(int n)
{
return n + 1;
}
learner@embeddex:~/lab$ # the prototype lets the compiler check the call before the definition a
ppears
learner@embeddex:~/lab$ gcc -o plus plus.c
learner@embeddex:~/lab$ # main calls plus_one(10) and prints the result
learner@embeddex:~/lab$ ./plus
10 + 1 is 11Passing by value, const, and what C cannot do
3 min readThis single rule, called pass-by-value, explains a surprise that trips almost every beginner. Consider:
void increment(int a)
{
a++; /* only the copy changes */
}
int main(void)
{
int i = 10;
increment(i);
printf("i == %d\n", i); /* prints 10, not 11 */
return 0;
}
Inside increment, a starts as a copy of i, so the increment changes a and leaves i untouched. When the function returns, a is discarded and i is still 10. The only way to give a value back is to return it, as plus_one did. This is why increment is a bug in waiting: it promises to increment but cannot, because it received a copy.
C has no pass-by-reference. There is no syntax that makes a parameter refer to the caller's variable. What C offers instead, and what the next lesson develops fully, is to pass a pointer: hand over the address of the variable, and let the function write through that address. For now the takeaway is simpler: passing a scalar gives the function a copy, and if you need a changed value back, either return it or (soon) pass a pointer.
The const qualifier has a precise meaning here. Writing int plus_one(const int n) tells the compiler that the function will not modify its parameter, which is enforced by the compiler. On a scalar parameter it is mostly documentation, since modifying the copy would not affect the caller anyway. const becomes far more useful once pointers arrive, where const int *p promises not to modify the data the pointer points at. Use const wherever a function should not change a value; it is a promise the compiler checks for you.
There is no mechanism in C that lets a function reach out and change a caller's scalar variable directly. A return value, or a pointer, is the only channel. Remember this now and the pointer lessons will feel obvious rather than magical.
learner@embeddex:~/lab$ # increment() changes only its local copy a
learner@embeddex:~/lab$ cat inc.c
#include <stdio.h>
void increment(int a)
{
a++;
}
int main(void)
{
int i = 10;
increment(i);
printf("i == %d\n", i);
return 0;
}
learner@embeddex:~/lab$ # compile it
learner@embeddex:~/lab$ gcc -o inc inc.c
learner@embeddex:~/lab$ # i is still 10: the copy changed, not the caller's variable
learner@embeddex:~/lab$ ./inc
i == 10The call stack and stack frames
3 min readYou do not need to write a line of assembly to benefit from this mental model, and it is the foundation for the pointer and debugging lessons to come. When main calls plus_one(10), the machine performs a few steps: it evaluates the argument, then makes room for a new the block of stack memory holding one function call's arguments, return address, saved registers and local variables on the a region of memory, usually growing downward, where each function call pushes a frame and each return pops one.
A frame holds four kinds of thing. The arguments, copied from the call. The return address, which records the instruction in the caller to resume after the function returns. Any saved register values, so the caller's state survives. And the function's local variables, which exist only for the life of that one call. When the function returns, its frame is released and control jumps back to the saved return address.
This is why local variables are private and short-lived, and why each call has its own copy of a parameter. It also explains recursion: a function that calls itself simply creates a new frame for each call, so there can be many frames for the same function at once, each with its own locals. On typical systems the stack grows downward in memory, with the newest frame at the lowest address.
Evaluate arguments: the caller computes the value of each argument expression.
Copy into parameters: each value is copied into the corresponding parameter of the callee.
Save the return address: the address of the instruction after the call is recorded so execution can resume.
Jump to the function: control transfers to the first instruction of the function body.
Run the body: the function executes, using its parameters and local variables in the new frame.
Return the value: the return expression is evaluated and its value is made available to the caller.
Pop the frame: the frame is released and execution resumes at the saved return address.
The full treatment of how a compiler lays out these frames, and how a buffer overflow can smash a saved return address, comes in the system-programming module. For today the model is enough: every call creates a frame, and the debugger you meet later in this lesson simply reads those frames back to you.
Headers, include guards and a first multi-file program
4 min readTwo ideas need separating, and getting them wrong is the most common build error in C. A a statement that tells the compiler a name and its type exist, without creating the object or function body says "this name exists, with this type". A a declaration that also creates the object or supplies the function body, so it allocates storage or emits code additionally creates the thing. A function prototype is a declaration; the function with its body is the definition. A variable can be declared extern many times but must be defined exactly once.
A header file is where declarations live. Its job is to give every source file the signatures it needs without duplicating them by hand. You include a header with #include, and there are two forms that differ only in where the compiler searches. Angle brackets search the system include directories, and are for the standard library:
#include <stdio.h>
#include <stdlib.h>
Double quotes search the current directory first, then the same places, and are for your own headers:
#include "bar.h"
Now the trap: if a header is included more than once, its declarations appear twice and you get redefinition errors, and if two headers include each other you get an infinite include cycle. The fix is an a pair of preprocessor directives that make a header compile its contents only the first time it is included:
#ifndef BAR_H /* if BAR_H is not defined... */
#define BAR_H /* ...define it... */
int add(int, int); /* ...and keep the contents */
#endif /* end of the guard */
The first include defines BAR_H and keeps the contents. Every later include finds BAR_H already defined and skips to #endif. The name is a convention: the file name upper-cased with the dot turned into an underscore. Do not start it with an underscore followed by a capital letter, because those names are reserved.
There is also #pragma once, a single line at the top of a header that tells the compiler to include it only once per compilation. It is non-standard but supported by gcc, clang and MSVC, and is the common modern choice. The #ifndef guard is the fully portable fallback, and many projects use both or choose one. The point is to always have one of them.
Your first multi-file program puts this together. A header declares a function, one source defines it, another calls it:
/* bar.h */
#ifndef BAR_H
#define BAR_H
int add(int, int);
#endif
/* bar.c */
#include "bar.h"
int add(int x, int y)
{
return x + y;
}
/* foo.c */
#include <stdio.h>
#include "bar.h"
int main(void)
{
printf("%d\n", add(2, 3));
return 0;
}
1compile all the sources together
gcc -o foo foo.c bar.c
./foo
Each source file, together with everything it includes, forms a translation unit, one source file after the preprocessor has expanded its includes, compiled as an independent unit. foo.c and bar.c are compiled separately and then linked, and the linker matches the call to add in foo.o with its definition in bar.o. In a later lesson you will compile each file to an object file with gcc -c so that only changed files are rebuilt.
Write an include guard or #pragma once in every header you create, without exception. It costs three lines and prevents a class of build errors that are otherwise very hard to trace.
learner@embeddex:~/lab$ # the header declares add and guards against double inclusion
learner@embeddex:~/lab$ cat bar.h
#ifndef BAR_H
#define BAR_H
int add(int, int);
#endif
learner@embeddex:~/lab$ # foo.c includes the header and calls add; bar.c supplies the body
learner@embeddex:~/lab$ cat foo.c
#include <stdio.h>
#include "bar.h"
int main(void)
{
printf("%d\n", add(2, 3));
return 0;
}
learner@embeddex:~/lab$ # compile both sources together and link
learner@embeddex:~/lab$ gcc -o foo foo.c bar.c
learner@embeddex:~/lab$ # add(2, 3) returns 5
learner@embeddex:~/lab$ ./foo
5The C preprocessor, from #include to function-like macros
3 min readYou have already used two of its directives. #include pastes a file's contents in place, and #define creates a a name the preprocessor replaces with a replacement list wherever it appears, before compilation. The simplest macro is object-like, a name for a value:
#define MAX_ITEMS 16
#define HELLO "Hello, world"
Wherever MAX_ITEMS appears, the preprocessor substitutes 16, as if you had typed it. A macro is untyped and purely textual: if the result is not valid C, the compiler complains after the substitution.
Conditional compilation lets the preprocessor keep or drop blocks of code before the compiler sees them. This is a compile-time decision, unlike an if statement, which runs at program time:
#define EXTRA_HAPPY
#ifdef EXTRA_HAPPY
printf("I'm extra happy!\n");
#else
printf("I'm just regular\n");
#endif
Because EXTRA_HAPPY is defined, only the first printf is compiled. The companions are #ifndef (if not defined), #elif, #else and #endif, plus #undef to remove a definition. A general #if tests an expression, and #if 0 ... #endif is the standard way to comment out a large block, since ordinary comments do not nest. The predefined macros __FILE__, __LINE__ and __func__ name the current file, line and function, and are how error messages report where they came from.
A function-like macro takes arguments that are substituted textually:
#define SQUARE(x) x * x
The reason this is wrong is the heart of macro discipline. SQUARE(3 + 4) expands to 3 + 4 * 3 + 4, and because multiplication binds tighter than addition, that is 3 + 12 + 4 = 19, not 49. Wrap each parameter and the whole thing in parentheses:
#define SQUARE(x) ((x) * (x))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
That fixes precedence but not side effects. MAX(x++, y) expands so that x++ appears twice, so x can be incremented twice, or once, depending on which branch runs. The rule: never pass an argument with a side effect, like x++ or a function call, to a macro.
Going deeperMultiple evaluation, and the do { } while (0) trick
A function-like macro is substitution, so an argument that appears twice in the replacement list is evaluated twice. MAX(x++, y) turns into ((x++) > (y) ? (x++) : (y)); whichever side wins is evaluated a second time, so a single increment can happen twice. This is why a macro that looks like a function is not one, and why modern C prefers an inline function for anything with logic. A related trick appears in multi-statement macros: writing #define F(x) { (x)++; } then using it as if (i) F(i); else ... breaks, because the trailing semicolon ends the if and orphans the else. The fix is to wrap the macro in do { ... } while (0), which absorbs the trailing semicolon and behaves like a single statement. You will see do { } while (0) throughout real headers for exactly this reason.
learner@embeddex:~/lab$ # SQUARE_BAD has no parentheses; SQUARE_OK wraps every operand
learner@embeddex:~/lab$ cat square.c
#include <stdio.h>
#define SQUARE_BAD(x) x * x
#define SQUARE_OK(x) ((x) * (x))
int main(void)
{
printf("bad: %d\n", SQUARE_BAD(3 + 4));
printf("good: %d\n", SQUARE_OK(3 + 4));
return 0;
}
learner@embeddex:~/lab$ # compile it
learner@embeddex:~/lab$ gcc -o square square.c
learner@embeddex:~/lab$ # 3 + 4 * 3 + 4 is 19; ((3 + 4) * (3 + 4)) is 49
learner@embeddex:~/lab$ ./square
bad: 19
good: 49Standard library headers: a guided tour
3 min readYou have met stdio.h. It declares the standard input and output functions that work with the three default streams, stdin, stdout and stderr: printf, scanf, putchar and fgets, plus the type FILE and fopen, fclose, fprintf for working with files. stdout is the normal output stream and stderr is the separate stream for error messages.
stdlib.h is the grab-bag of essentials: malloc and free for dynamic memory (which you will use in a later session), exit to end a program, atoi and atof to parse numbers from strings, rand for pseudo-random numbers, and EXIT_SUCCESS and EXIT_FAILURE for main.
string.h works on blocks of memory and character strings: strlen measures a string, strcpy and strcat copy and join them, strcmp compares them, and memcpy, memmove and memset copy and fill raw bytes. These are some of the most bug-prone functions in C because they do no bounds checking, a theme the pointers lesson returns to.
math.h declares the floating-point functions sqrt, pow, sin, cos, log, floor, ceil and fabs. It is the one header that needs an extra link step:
gcc -o prog prog.c -lm
The -l flag links a library, and m names libm, the maths library. On most systems the maths functions live in a separate library that gcc does not link by default, which is why using sqrt without -lm fails at link time with an undefined reference. This is a deliberate historical split, and the error message looks confusing until you know to add -lm.
limits.h holds the limits of the integer types, such as INT_MAX, INT_MIN, UINT_MAX and CHAR_BIT, so your code can know the range of an int without guessing. stdbool.h provides the bool type and the constants true and false for readable conditions.
When a build fails with a message naming a function and the words "undefined reference", the compiler found the declaration but the linker could not find the definition. For a library function, add the right -l flag, most often -lm for maths. For your own function, you forgot to list its source file on the command line.
learner@embeddex:~/lab$ # m.c calls sqrt from math.h
learner@embeddex:~/lab$ cat m.c
#include <stdio.h>
#include <math.h>
int main(void)
{
double x = 9.0;
printf("sqrt(9) = %f\n", sqrt(x));
return 0;
}
learner@embeddex:~/lab$ # no -lm, so the linker cannot find sqrt
learner@embeddex:~/lab$ gcc -o m m.c
/usr/bin/ld: /tmp/cc9urx1X.o: in function `main':
m.c:(.text+0x23): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
learner@embeddex:~/lab$ # link the maths library with -lm
learner@embeddex:~/lab$ gcc -o m m.c -lm
learner@embeddex:~/lab$ # now the call resolves and prints the square root
learner@embeddex:~/lab$ ./m
sqrt(9) = 3.000000Starting gdb: breakpoints and stepping
4 min readA debugger cannot show you source lines unless the compiler recorded how machine code maps back to them. Compile with -g:
gcc -g -o foo foo.c bar.c
The -g flag writes debug information into the executable. Without it, gdb still runs the program but reports addresses and assembly instead of your variable names and lines. Start the debugger with the program as its argument:
gdb ./foo
You are now at the (gdb) prompt. A a marker at a function or source line where the debugger pauses the program when execution reaches it is where execution stops. Set one at the start of main, or at a specific line, then run. The addresses shown are typical and will differ on your machine:
(gdb) break main
Breakpoint 1 at 0x1151: file foo.c, line 5.
(gdb) run
Starting program: /home/learner/foo
Breakpoint 1, main () at foo.c:5
5 printf("%d\n", add(2, 3));
The small address shown before run is an offset, not the final address: Ubuntu builds position-independent executables (PIE) by default, so the real address is fixed only when the program is loaded, typically around 0x555555555000 under gdb, which turns off address randomisation while you debug.
The program stopped just before executing line 5. Now you control it. next (or n) runs the current line and stops on the next line in the same function, stepping over any function calls it contains. step (or s) also runs one line, but if that line calls a function, it steps into that function and stops on its first line. continue (or c) resumes until the next breakpoint or the end. finish runs until the current function returns and prints its return value. quit ends the session.
Compile with -g: gcc -g -o foo foo.c bar.c embeds the debug information gdb needs.
Start gdb: gdb ./foo opens the (gdb) prompt with the program loaded but not yet running.
Set a breakpoint: break main or break foo.c:5 marks where execution should pause.
Run: run starts the program, which stops when it reaches the breakpoint.
Step: step enters a call and next steps over it, one source line at a time.
Continue or finish: continue resumes to the next breakpoint, and finish runs until the current function returns.
ange x
learner@embeddex:~/lab$ cat calc.c
#include <stdio.h>
int add(int x, int y)
{
int s = x + y;
return s;
}
int main(void)
{
int a = 2;
int b = 3;
int r = add(a, b);
printf("%d\n", r);
return 0;
}
learner@embeddex:~/lab$ # gcc -g writes DWARF debug info gdb reads back as source lines
learner@embeddex:~/lab$ gcc -g -o calc calc.c
learner@embeddex:~/lab$ # break at add, run, print the argument, read the backtrace, change x an
d watch the output become 23
learner@embeddex:~/lab$ gdb -q -batch -ex 'break add' -ex 'run' -ex 'print x' -ex 'backtrace' -e
x 'set variable x = 20' -ex 'next' -ex 'print s' -ex 'continue' ./calc
bash: gdb: command not foundExamining state: print, backtrace and frames
3 min readThe workhorse is print (or p), which evaluates an expression in the current frame. The values below are illustrative:
(gdb) print x
$1 = 7
(gdb) print x + y
$2 = 10
print accepts any expression the program could evaluate, including one that calls a function. The $1, $2 are value-history numbers, and a bare print repeats the last value. A related command is display, which registers an expression to be printed automatically every time execution stops, and undisplay removes it. That is how you watch a variable change as you step without retyping print each time.
The a listing of the currently active stack frames, innermost first, showing how the program reached its current point, backtrace or bt, shows the call stack:
(gdb) bt
#0 add (x=2, y=3) at bar.c:6
#1 0x0000555555555182 in main () at foo.c:5
Frame #0 is the innermost, the function currently executing, and each number up is its caller. info locals lists the local variables of the selected frame and info args lists its arguments. list (or l) prints source around the current line, and list foo.c:10 shows a specific place.
Because many gdb commands act on one selected frame, you can move between frames. up moves toward the caller and down toward the callee; frame 2 jumps straight to a frame number. After up into main, print shows main's variables, because each frame has its own locals. This is the same privacy you saw on the call stack, made visible.
Finally, set variable changes a value in the running program:
(gdb) set variable x = 9
The next time the program reads x, it reads 9. This is how you test a fix without recompiling, and it is the essence of the lab for this session: change a variable mid-run and watch the program's output change.
Changing a variable with set affects the running program and its output, but it does not edit your source file. After you have used it to confirm a diagnosis, make the same change in the source and rebuild, or the fix vanishes when the program next runs.
TUI, .gdbinit, and the real-world debugging traps
4 min readThe TUI, text user interface, is enabled with gdb -tui or by typing tui enable inside gdb. The layout command chooses the panes: layout src shows source, layout asm shows disassembly, layout regs adds the registers, and layout split shows source and assembly together. C-x a toggles the whole TUI on and off. It is the quickest way to see both your code and the machine's state at once, and it uses the same commands as plain gdb.
Settings you want on every run live in a .gdbinit file. gdb reads ~/.gdbinit in your home directory automatically, and you can put things there like set pagination off, set history save on, or a layout src. A project-local ./.gdbinit is not loaded automatically by modern gdb for security, since a cloned project could otherwise run arbitrary commands when you start the debugger; you must approve its path with set auto-load safe-path. Keep your personal defaults in ~/.gdbinit.
Now the traps that cost professionals time, in symptom, cause and fix form.
"optimized out", and stepping that jumps around. Symptom: a variable you know exists prints <optimized out>, or step skips lines and runs them out of order. Cause: the program was built with -O2 or another optimisation flag. The compiler reorders, merges and removes code, and variables that are not needed in registers are not kept in a readable form. Diagnosis: check your build command for -O; gdb may also show the value as <optimized out> in a backtrace. Fix: debug at -O0, the default, and only turn optimisation on once the program is correct. The debug information maps code to source, but it cannot undo what the optimiser did.
A breakpoint on a call site never triggers. Cause: the function was inlined, so there is no call instruction at that line. gdb usually reports that it moved the breakpoint to a later line. Fix: set the breakpoint on a line inside the function instead.
The debugger shows assembly instead of source. Cause: the program was built without -g, so there is no source line mapping. Fix: recompile with gcc -g.
Going deeperDWARF: what -g actually writes
The -g flag does not change your source and does not store your .c file in the executable. It makes the compiler emit debug information in a standard format called DWARF, for Debugging With Attributed Record Formats, into dedicated sections of the object and executable files. Those sections record, for each machine instruction, which source file, line and function it came from, plus the name, type and location of every variable. gdb reads these sections at run time and uses them to translate the program counter back into foo.c:5 and to find where a variable lives. This is why debug information lives in the ELF file rather than the source, and why a program built with -g is larger: the mapping tables travel with it. The full ELF and DWARF layout is the subject of a dedicated lesson later in the program.
Going deeperCalling conventions: registers versus the stack
When the compiler turns a call into machine code, it follows an ABI, an application binary interface, that fixes how arguments and return values are passed. On 64-bit x86, the System V AMD64 ABI, the first six integer or pointer arguments go in the registers RDI, RSI, RDX, RCX, R8 and R9, further arguments go on the stack, and the return value comes back in RAX. The older 32-bit cdecl convention pushed every argument on the stack right to left, with the caller cleaning up afterwards. This is why a function with few integer arguments does not use the stack for its arguments at all, and it is the first thing you will recognise when you read disassembly in a later lesson. On an ARM board the convention differs again, which is one reason cross-compiled code cannot share a calling convention with x86 code.
Try it
1 min readOpen the lab for this session and build the two-file program from this lesson: a header with an include guard declaring a function, a source file defining it, and a main that calls it, then compile with gcc -o foo foo.c bar.c and run it. Next, compile the same program with gcc -g and drive a gdb session end to end: set a breakpoint, run, step into the function, print its arguments, and read a backtrace with bt. Then use set variable to change a value mid-run and confirm the program's output changes, exactly as in the gdb manual's sample session. The practice pack walks through each step and the checks above, from why increment(i) prints 10 to what "optimized out" means and how to fix it.
Key takeaways
- A prototype declares a function's signature, the definition supplies its body, and a call copies each argument into a parameter.
- C passes everything by value, so a function cannot change the caller's variable unless you pass a pointer to it.
- A stack frame holds a call's arguments, return address and locals; a backtrace is just the list of frames still on the stack.
- Include guards and #pragma once stop a header from being included twice, which prevents duplicate-definition errors.
- The preprocessor does textual substitution before the compiler runs, which is why macros need parentheses and hate side effects.
- gcc -g writes DWARF debug information into the ELF file, which gdb reads to map machine code back to your source lines.
- step steps into a call and next steps over it; print, backtrace and info locals reveal state, and set changes it.
- Optimized code reorders and inlines, so variables can read as 'optimized out'; debug at -O0 first, then turn optimisation on.
Reflect
- Explain to a colleague, in two sentences: define a function with a return type and parameter list, declare it with a prototype, and call it.
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- Official docsGCC online documentation: Options for Debugging Your Program (-g)
- Official docsThe C Preprocessor (cpp) manual
- Man pagegdb(1) - Linux man page
- Man pagemath.h - POSIX header overview
- SpecificationDWARF Debugging Information Format, Version 5
- SpecificationSystem V Application Binary Interface: AMD64 Architecture Processor Supplement
Official documentation first. Links checked when the lesson was published.