News for hackers. Stuff that matters.
Re:Simple Dynamic Strings library for C, compatible with nul... by cryptonector on Tuesday December 03, 2019 @01:10PM (#21694886)
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.
Re:Simple Dynamic Strings library for C, compatible with nul... by shawxe on Tuesday December 03, 2019 @01:25PM (#21695035)
This 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.
Re:Simple Dynamic Strings library for C, compatible with nul... by cryptonector on Tuesday December 03, 2019 @02:44PM (#21695908)
Yeah, but almost perfect ergonomics is good enough, and type safety >> ergonomics.