3 ms·
The right way to do this would be: typedef struct sds { char *s; } sds; Now you get type safety: you can't accidentally pass a plain 'ole C string to
by cryptonector 7y ago
The right way to do this would be:
typedef struct sds {
char *s;
} sds;
Now you get type safety: you can't accidentally pass a plain 'ole C string to an sds function. But you do need to access the 's' field to get the C string for passing to non-sds functions.
- shawxe 7y agoThis is fine, but it somewhat defeats the purpose of the opaquely prefixed header. I think the idea is just to be able to treat an SDS like a normal string. Unfortunately, there's no way to have that property not be commutative in C.
- cryptonector 7y agoYeah, but almost perfect ergonomics is good enough, and type safety >> ergonomics.