Skip to content

Commit ac549a6

Browse files
Update cnullptr.h
1 parent 0f353a9 commit ac549a6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

code/logic/fossil/sys/cnullptr.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ extern "C" {
113113
#endif
114114
#endif
115115

116+
/**
117+
* @brief Annotations for nullable and nonnull pointers.
118+
*
119+
* These macros provide compiler hints about pointer validity, improving static analysis and safety.
120+
*
121+
* - **GCC/Clang:** Uses `__attribute__((nullable))` and `__attribute__((nonnull))`
122+
* - **MSVC:** Uses `_Null_terminated_` and `_In_` (though `_In_` is not strictly equivalent to nonnull)
123+
* - **Fallback:** If the compiler does not support these attributes, it defines empty macros.
124+
*/
125+
#if defined(__clang__) || defined(__GNUC__)
126+
#define cnullable __attribute__((nullable))
127+
#define cnonnull __attribute__((nonnull))
128+
#elif defined(_MSC_VER)
129+
#define cnullable _Null_terminated_ // Not a perfect match, but useful for MSVC
130+
#define cnonnull _In_ // MSVC does not have a direct `nonnull` equivalent
131+
#else
132+
#define cnullable
133+
#define cnonnull
134+
#endif
135+
116136
// Termination values for regular and wide strings
117137

118138
/**

0 commit comments

Comments
 (0)