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.
Goal: determine whether a signed integer overflow check written in C source can be expected to survive compilation at different optimization levels, given that signed overflow remains undefined behavior from C89 through C23. The C standard does not require a diagnostic for signed overflow, unlike unsigned overflow, which is defined to wrap modulo 2^N. GCC an
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.