@@ -78,16 +78,33 @@ extern "C" {
7878// Ensure null pointer definitions across C and C++ environments
7979#ifndef FOSSIL_CNULL
8080
81- #if __cplusplus >= 201103L || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
8281/* *
83- * @brief Safe null pointer definition for modern C++ and C23.
82+ * @brief Safe and consistent null pointer definition for modern C++ and C standards.
83+ *
84+ * This section defines `cnull` and `cnullptr` for both C and C++ environments.
85+ * The definitions ensure compatibility across different language versions, providing
86+ * a clear and consistent way to represent null pointers.
87+ *
88+ * - **C++11 and Later:** If the code is compiled using C++11 (`__cplusplus >= 201103L`)
89+ * or newer, `nullptr` is used. `nullptr` is a type-safe null pointer constant that
90+ * prevents accidental misuse in pointer arithmetic or type ambiguities.
91+ *
92+ * - **C23 and Later:** In C23 (`__STDC_VERSION__ >= 202311L`), `nullptr` is introduced
93+ * as a type-safe null pointer constant, mirroring the C++ equivalent. The `cnull`
94+ * and `cnullptr` macros directly map to this standard definition.
95+ *
96+ * - **Older C Standards (C11 and Below):** If neither C23 nor C++11 is detected,
97+ * `cnull` and `cnullptr` are defined using `((void*)0)`, which is the traditional
98+ * and portable representation of a null pointer in C.
99+ *
100+ * This abstraction guarantees that null pointer values are handled consistently
101+ * across different compilers and platforms, reducing the risk of undefined behavior
102+ * in pointer operations.
84103 */
104+ #if __cplusplus >= 201103L || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
85105 #define cnull nullptr
86106 #define cnullptr nullptr
87107#else
88- /* *
89- * @brief Platform-agnostic null pointer definition for older C standards.
90- */
91108 #define cnull ((void *)0 )
92109 #define cnullptr ((void *)0 )
93110#endif
0 commit comments