Using Compound Literals in C: Create Temporary Objects Safely
A concise guide to using C compound literals: syntax, lifetime, and pitfalls. Learn how to create temporary objects safely and avoid compile‑time errors or undefined behavior.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
A concise guide to using C compound literals: syntax, lifetime, and pitfalls. Learn how to create temporary objects safely and avoid compile‑time errors or undefined behavior.
Use C11 _Generic to create a zero‑overhead abs macro that selects the correct library function for int, long, float, and double arguments.
A C struct holding 13 bytes of data can quietly occupy 24. Here is how to measure padding with sizeof and offsetof, and reclaim the waste by reordering members.
Learn how to replace heavy mutexes with C11 atomic types to build high-performance, thread-safe counters using lock-free synchronization and memory ordering.
Learn how C11’s _Generic keyword lets you write a single type‑generic macro—illustrated with an abs() example—and understand its trade‑offs and verification steps.
Learn how C11’s _Generic keyword lets you write a single, type‑safe macro that expands to the correct abs‑family function for int, long, float, or double, with zero runtime cost.
Stop relying on member order in C structs. Designated initializers (.member = value) let you name fields at compile time, reducing bugs and improving readability.
Learn how to implement a high-throughput circular buffer in C using power-of-two masking and atomic indices to achieve O(1) performance without dynamic memory allocation.
Speed up your C memory copy by using the C99 <code>restrict</code> keyword. Learn how it works, see a concrete example, understand trade‑offs, and validate the performance gains in a few steps.