News for hackers. Stuff that matters.
Re:How can C Programs be so Reliable? by Hexstream on Tuesday November 11, 2008 @09:20PM (#361275)
But oftentimes I want a correct result or an obvious failure, without having to handle tons of errors I don't even want to account for.
Re:How can C Programs be so Reliable? by holygoat on Tuesday November 11, 2008 @09:45PM (#361306)
Returning -1 is an obvious failure.

What you're saying is that you want your programs to blow up when a function returns a known error (such as "disk full").

One of the points of the article is that C makes you think about all the possible, well-documented, errors that each function can encounter. You know when you write C precisely what can go wrong at each stage, and decide the right way to handle it.

Seeing a dialog box pop up with some exception backtrace is one of the things that annoys me about 'modern' Java-esque languages: they seem to encourage developers to default to ignoring most exceptions.

Re:How can C Programs be so Reliable? by aaronblohowiak on Wednesday November 12, 2008 @12:07AM (#361431)
Defensive programming vs. `Let it fail`.

I think the space between to two is more uncomfortable than either extreme.

Re:How can C Programs be so Reliable? by wheels on Wednesday November 12, 2008 @12:36AM (#361463)
Interestingly, I noticed earlier this week that the new GCC gives warnings when the return values of POSIX / libc functions are ignored but shouldn't be.
Re:How can C Programs be so Reliable? by maw on Wednesday November 12, 2008 @03:42PM (#362285)
Which versions of gcc and libc? Any special flags passed to gcc? I ask because I just tried it with a test program here (openSUSE Factory, gcc 4.3.3 and glibc 2.8.90) and it didn't print any warnings, but it would be nice if it did.
Re:How can C Programs be so Reliable? by janm on Wednesday November 12, 2008 @07:13AM (#361733)
The difference between letting an exception bubble up and seeing a system call fail and aborting is pretty small. Either way, you need a higher level way of dealing with it.

One of the most interesting papers I read was "Why computers fail and what we can do about it" by Jim Gray while he was at Tandem. Transactions are essential, and most failures are transient. This can be applied at many levels, and can deal with many failures without the developer of the mainline code having to decide what to do for each given failure.

Re:How can C Programs be so Reliable? by etal on Wednesday November 12, 2008 @12:14AM (#361437)
Exactly. In properly written C, about half your code is checking for errors and handling them explicitly. If you don't do that, at some point it will blow your foot off; you have to account for those errors. C programmers have generally accepted this and thus spend an excessive amount of coding time thinking about and writing recovery mechanisms for external errors -- and that's why so many C programs are incredibly stable.
Re:How can C Programs be so Reliable? by janm on Wednesday November 12, 2008 @07:14AM (#361734)
Yes.