2 ms·
Could you provide an example? Either source code or a link. I want to see how you might define a type for "guaranteed to not be null pointer to char".
by chongli 8y ago
Could you provide an example? Either source code or a link. I want to see how you might define a type for "guaranteed to not be null pointer to char".
- kzrdude 8y agoI'm thinking of just: struct char_nonnull_t { char *ptr; }; char *char_nonnull_as_pointer(struct char_nonnull_t cp) { return cp.ptr; } With the required extra accessor functions. Of course in C, we don't have generics, data hiding or other nice features, so we have to build a wall of conventions around our types instead. Types with invariants are totally possible in C. We just don't have a way to automatically enforce them. It's C, after all.