Advanced C
Macros, the memory model, concurrency, low-level tricks, linking, debugging tools and safety standards.
This is an overview — pick a sub-topic below.
Sub-topics (22)
Preprocessor Macros
`#define` creates object-like and function-like macros expanded before compilation.
Conditional Compilation
`#if`, `#ifdef`, `#elif`, `#else` include code only for certain builds.
Macro Pitfalls
Macros are text substitution — missing parentheses, double evaluation and swallowed semicolons cause bugs.
C Memory Model
The rules for what values threads can see when they share memory (C11).
volatile in Depth
`volatile` forces every access to really happen — for memory-mapped registers and variables changed by interrupts.
Atomics
Indivisible operations with defined memory ordering (`stdatomic.h`).
Concurrency Basics in C
Threads share memory; protect shared data with mutexes or atomics and avoid deadlocks.
C11 Threads
`threads.h`: `thrd_create`, `mtx_lock`, `cnd_wait` — portable threads (where supported).
Signals in C
OS notifications sent to a process (SIGINT, SIGTERM, SIGSEGV), handled with `signal`/`sigaction`.
setjmp and longjmp
Save a point in execution and jump back to it later — non-local error recovery.
Bit Manipulation in C
Set, clear, toggle and test bits with masks.
Endianness
The byte order of multi-byte values in memory: little-endian (x86, ARM) vs big-endian (network order).
ABI
The Application Binary Interface: how compiled code agrees on type sizes, alignment, calling conventions and symbol names.
Calling Conventions
Rules for passing arguments and return values in registers/stack and who saves which registers.
Linking
The linker resolves symbols between object files and libraries and lays out the final program.
Static Libraries
Archives of object files (`.a`, `.lib`) copied into the executable at link time.
Shared Libraries
Libraries loaded at run time (`.so`, `.dll`, `.dylib`) shared between programs.
Debugging with GDB
Step through C programs, inspect variables and find crashes.
Sanitizers
Compiler instrumentation that catches bugs at run time: AddressSanitizer, UndefinedBehaviorSanitizer, ThreadSanitizer.
Valgrind
Runs a program on a virtual CPU to detect memory errors and leaks (Linux).
MISRA C
Coding guidelines for safety-critical C (automotive, medical, aerospace).
Secure C Coding
Avoid buffer overflows, format-string bugs, integer overflows and use-after-free.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.