C · Expert
Strict aliasing allows the compiler to assume that pointers of different types do not alias the same memory. The 'restrict' qualifier (C99) explicitly informs the compiler that for the lifetime of…
performancebestpractices
Open snippet →C · Expert
A flexible array member is an unsized array declaration at the end of a struct. It allows for a single contiguous memory allocation for both the metadata (header) and the payload (data). This avoid…
arraysmemory
Open snippet →C · Expert
The 'volatile' qualifier prevents the compiler from caching a variable's value in a register, forcing it to read from memory every time. 'sig_atomic_t' is a type that can be accessed as an atomic e…
syntaxmemory
Open snippet →C · Expert
Opaque pointers (often called 'handles' or the PIMPL idiom) allow for complete data encapsulation in C. By only providing a forward declaration in the header and defining the structure in the sourc…
functionsbestpractices
Open snippet →C · Expert
The X-Macro pattern is a powerful preprocessor technique used to maintain multiple related lists (like enums, strings, or switch cases) in sync. You define a list once and then 'apply' it by redefi…
syntaxbestpractices
Open snippet →C · Expert
Uses C11's stdatomic.h to perform a lock-free update. atomic_compare_exchange_weak checks if the current value matches 'expected'; if so, it updates it to 'desired'. If not, it updates 'expected' w…
memoryperformance
Open snippet →C · Expert
Compound literals allow creating unnamed objects on the fly. They are lvalues, meaning you can even take their address. This is extremely useful for passing complex arguments to functions without c…
syntaxmemory
Open snippet →C · Expert
The __VA_ARGS__ identifier is used in the macro expansion to represent the variable arguments passed to the macro. This allows creating powerful wrappers around functions like printf while automati…
syntaxfunctions
Open snippet →C · Expert
Introduced in C11, _Static_assert allows checking conditions at compile time rather than runtime. If the expression is false, the compiler generates an error with the provided string, ensuring that…
syntaxbestpractices
Open snippet →C · Expert
Designated initializers allow you to initialize specific array indices or struct members by name/index. For arrays, this is particularly useful for mapping non-sequential constants (like error code…
syntaxarrays
Open snippet →C · Expert
Introduced in C11, the _Thread_local storage class specifier defines variables that have thread storage duration. Each thread receives its own separate instance of the variable, initialized once pe…
memoryperformance
Open snippet →C · Expert
Using a pointer to an array with a variable size (VLA) as a function parameter allows for natural multidimensional indexing (matrix[i][j]) while maintaining type safety. Unlike a pointer-to-pointer…
arraysfunctions
Open snippet →C · Expert
The _Noreturn keyword (C11) indicates that a function will not return to its caller, typically because it terminates the program or performs a long jump. This provides a hint to the compiler for op…
functionscontrolflow
Open snippet →C · Expert
In C, arithmetic operations on types smaller than 'int' (like char or short) trigger 'integer promotion', converting the operand to an 'int' first. Performing a bitwise NOT (~) on an unsigned char…
datatypessyntax
Open snippet →C · Expert
The result of subtracting two pointers is of the signed integer type 'ptrdiff_t'. This operation is only defined if both pointers point to elements within the same array or one past the last elemen…
memorydatatypes
Open snippet →C · Expert
Introduced in C11, _Generic provides a way to write type-generic macros. It acts like a compile-time switch statement that selects an expression based on the type of a controlling expression, allow…
syntaxfunctions
Open snippet →C · Expert
setjmp and longjmp allow for non-local jumps that bypass the standard function call/return mechanism. This is often used to implement exception-like error recovery where a deeply nested function ca…
controlflowfunctions
Open snippet →C · Expert
Opaque pointers (or 'PIMPL' in C) hide the implementation details of a struct from the user. By only providing a forward declaration in the header, the compiler prevents users from accessing intern…
oopbestpractices
Open snippet →C · Expert
X-Macros are a preprocessor technique for generating repetitive code from a single master list. This ensures that enums, string arrays, and other related structures remain synchronized, reducing ma…
syntaxbestpractices
Open snippet →C · Expert
Flexible Array Members (introduced in C99) allow a structure to end with an unsized array. This technique enables a single heap allocation to contain both the metadata header and the variable-lengt…
memoryarraysdatatypes
Open snippet →C · Expert
Bit-fields allow the definition of structure members with explicit bit widths. This is essential for hardware-level programming or compacting data for network protocols. However, bit-field layout i…
memoryperformancedatatypes
Open snippet →C · Expert
Function pointers enable polymorphism in C. By using 'void*' parameters in a callback signature, you can create generic algorithms (like qsort) that operate on any data type. The callback abstracts…
functionsbestpractices
Open snippet →C · Expert
'sig_atomic_t' is an integer type that can be accessed as an atomic entity even in the presence of asynchronous interrupts (signals). Combined with 'volatile', it prevents the compiler from caching…
performancememorydatatypes
Open snippet →