News for hackers. Stuff that matters.
Re:Why should I have written ZeroMQ in C, not C++ (2012) by AnimalMuppet on Wednesday December 12, 2018 @09:10PM (#18669377)
So that at any given moment, you know which one you have.
Re:Why should I have written ZeroMQ in C, not C++ (2012) by kllrnohj on Thursday December 13, 2018 @06:49PM (#18677214)
Your example doesn't tell me which I have. It's assuming that err = 0 means success, but that's an assumption not a contract of the type.

By comparison some something like https://github.com/oktal/result will tell you if it's a success or error without any magic error codes that actually mean success.

You could do this with a type bit + union in C, it's just more painful without templates

Re:Why should I have written ZeroMQ in C, not C++ (2012) by Koshkin on Wednesday December 12, 2018 @10:01PM (#18669562)
That requires 1 bit of information, and there is often a way of embedding that bit in the value itself; but the general technique of representing alternatives is called “a tagged union.” (You can also hear the fancy terms “the product type” for the struct and “the sum type” for the union.)
Re:Why should I have written ZeroMQ in C, not C++ (2012) by lixtra on Wednesday December 12, 2018 @10:41PM (#18669705)
Accessing that one bit can be as expensive as passing an int around.