3 ms·
You could define a macro NOTNULL for this, to make it clearer to readers. void foo(char bar[static 1]) vs void foo(NOTNULL(char* bar)) Though I'm no
by jefftk 8y ago
You could define a macro NOTNULL for this, to make it clearer to readers.
void foo(char bar[static 1])
vs
void foo(NOTNULL(char* bar))
Though I'm not sure whether this can be expressed as a macro, since you need to remove the "*"?
- saagarjha 8y agoHow about this: #define NOTNULL void foo(NOTNULL char *bar) If you're using Objective-C, then nonnull is your friend.
- int_19h 8y agoThe point is to get [static 1] in the expansion of the macro, so that the compiler is aware too, not just the coder.
- saagarjha 8y agoAh. I was wondering why this was difficult; thanks for the clarification!
- 1over137 8y agoThe clang nullability annotations can be used in C/C++ as extensions: https://clang.llvm.org/docs/AttributeReference.html#nullability-attributes https://clang.llvm.org/docs/AttributeReference.html#nullabil... You could then conditionally define your NOTNULL using them or not. The compiler will then complain about incorrect usage.