C11 Atomic Counters: A Lock-Free Increment Example
Use C11 atomics to make a thread-safe increment-only counter without a mutex, plus compile flags, verification steps, and memory-order trade-offs.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Use C11 atomics to make a thread-safe increment-only counter without a mutex, plus compile flags, verification steps, and memory-order trade-offs.
C library authors face a trade-off between standard types, exact-width C99 types, and implementation-optimized variants. This guide compares them across portability, ABI stability, and serialization needs, then shows how to validate layout assumptions with compiler checks and sanitizers.
Load embedded media safely with SDL2 SDL_RWops: use read-only memory buffers for assets and treat filesystem paths as untrusted input.
Use snprintf instead of sprintf, pass the real buffer size, and check the return value to catch truncation before trusting a C string.
Learn how to use opaque pointers in C to hide internal struct members, enforce API boundaries, and improve binary compatibility by preventing direct data access.
Guide to choosing a type‑generic abs implementation in C11 using _Generic macros and inline functions, with trade‑offs, sample code, and verification steps.
Run Lua scripts from C, expose host functions, and shut down the Lua state safely.
Unchecked malloc returns still crash production C code. This post covers malloc, calloc, realloc, and free with a worked string-buffer example, the realloc trap, and a verification checklist using AddressSanitizer and Valgrind.
GCC's -flto lets the linker optimize across translation units, often shrinking release binaries at the cost of longer link times.