<div dir="ltr">On Sat, Dec 19, 2015 at 10:06 AM, Enrico Weigelt, metux IT consult <span dir="ltr"><<a href="mailto:enrico.weigelt@gr13.net" target="_blank">enrico.weigelt@gr13.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If C had constrainted subtypes, all of this would be pretty easy - we<br>
could let those functions return a subtype, which is constrainted to<br>
exactly the allowed values, so the compiler could check for that.<br></blockquote><div><br></div><div>I don't think undefined values are any problem. They will pass through unchanged in most code. Also I think you can pretty clearly state that functions that return values outside this set even if they call functions that all only return values inside the set, are in error.<br><br></div><div>The real problem is with the status is the inconsistency with true/false, making it too easy to write code that does the wrong thing, or that is hard to read. It would help if software was forced to write "foo() == OK", or to just make "if (status)" actually be true only when status is OK. But that can't be done with C, and even though C++ can make this happen it usually is not done that way, probably because it is still hard to read and too easy to make a mistake.<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
</span>Hmm, I don't think it's really consistent. Okay, you can simply pass the<br>
value up in the call hierarchy - but is that really so helpful ?<br></blockquote><div><br></div><div>That is actually pretty common:<br><br></div><div>   int status;<br>   status = foo();<br></div><div>   if (status != OK) return status;<br></div><div>   status = bar();<br></div><div>   if (status != OK) return status;<br></div><div>   status = baz();<br></div><div>   return status;<br></div><div><br></div><div>This also works if boolean success value is used consistently. But it gets difficult if there is a mix of types, which is probably why you are seeing resistance to changing some (but not all) functions to bool.<br><br></div></div></div></div>