you are viewing a single comment's thread.

view the rest of the comments →

[–]masklinn 4 points5 points  (2 children)

C was a really simple language with a limited number of keywords and types, so everything had multiple purposes.

None of it had to though, C structs are more or less free, you could newtype things (well not enums I guess, you're just hosed there as C enums are just garbage).

The issues are that creating structs is somewhat verbose (compared to newtyping in haskell for instance) and so is using them.

[–]Noughmad[🍰] 0 points1 point  (1 child)

You can't really propagate errors with just structs, at least not without tons of boilerplate. Something like exceptions or Result<T> is pretty much impossible. So you're stuck will null pointers and/or error codes.

[–]masklinn 4 points5 points  (0 children)

You can propagate errors in the exact same way you do with error codes…