logoalt Hacker News

fhdkweigtoday at 2:15 PM2 repliesview on HN

What if the number you want to return just happens to be the value of ERROR? You need an error flag that can't be represented as an int, but then C wouldn't let you return it from a function that only returns "int". It is why some languages throw exceptions and why databases have the special "null" value.


Replies

voidUpdatetoday at 2:27 PM

I don't use C enough to know what the convention is for throwing an error when the function can return a number anyway. You'd have to ask someone else

show 1 reply
jerftoday at 2:28 PM

And why some very, very special languages have an effectively-global variable called "errno" that you have to check after the call manually, and worry about whether maybe it was populated from some previous error. Nothing says "production-quality language that an entire civilization's code base should be based on" like "sometimes (but only sometimes!) functions return additional information through global values".

show 1 reply