2 ms·
I'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 requi
by kzrdude 8y ago
I'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.