News for hackers. Stuff that matters.
Re:How can C Programs be so Reliable? by 0x12 on Thursday September 22, 2011 @07:52AM (#3025725)
> I've seen plenty of code where I was like "WTF was this guy thinking?".

Yes, that happens. But I've seen that in COBOL, Perl, Pascal, Java, PHP and in Ruby as well.

> In case of errors (s)ome functions are returning 0. Some are returning -1.

That's not a feature of the language.

Re:How can C Programs be so Reliable? by bad_user on Thursday September 22, 2011 @08:32AM (#3025821)

     That's not a feature of the language.
Well, yes, but it's kind of nice when you've got exceptions with stack traces attached.

Some people don't like exceptions, but I do.

Re:How can C Programs be so Reliable? by ajross on Thursday September 22, 2011 @12:43PM (#3026674)
It is indeed "kind of nice". But the question at hand is whether it's a requirement for writing reliable software. I tend to agree with the posts here that argue that it's not. It saves time for developers, it doesn't meaningfully improve the quality of the end product.

Serious C projects tend to come up with this stuff on their own, often with better adapted implementations than the "plain stack trace" you see in higher level environments. Check out the kernel's use of BUG/WARN for a great example of how runtime stack introspection can work in C.

Re:How can C Programs be so Reliable? by 0x12 on Thursday September 22, 2011 @10:58AM (#3026273)
gdb: where
Re:How can C Programs be so Reliable? by mattgreenrocks on Thursday September 22, 2011 @08:40AM (#3025834)
No, but C could use more consistent error handling semantics, rather than conflating return values and error codes. Worse still: a combination of a return code and a global error code.
Re:How can C Programs be so Reliable? by praptak on Thursday September 22, 2011 @09:13AM (#3025922)
"Worse still: a combination of a return code and a global error code."

That's not the worst that exists in C :-) Let me quote a dietlibc developer from http://www.koders.com/c/fid1639C203A2255EB1FA11DC6A68D74FEB2...

    /* Oh boy, this interface sucks so badly, there are no  words for it.
    * Not one, not two, but _three_ error signalling methods!  (*h_errnop
    * nonzero?  return value nonzero?  *RESULT zero?)  The glibc goons
    * really outdid themselves with this one. */
Re:How can C Programs be so Reliable? by epo on Friday September 23, 2011 @05:21AM (#3029361)
And a comment written by a 13-year old proves what exactly?
Re:How can C Programs be so Reliable? by adobriyan on Thursday September 22, 2011 @09:25AM (#3025971)
But first function returning multiple values. Baby steps. :-)
Re:How can C Programs be so Reliable? by tbrownaw on Thursday September 22, 2011 @03:21PM (#3027388)
> In case of errors (s)ome functions are returning 0. Some are returning -1.

That's not a feature of the language.

The inconsistency is a natural, expected, unavoidable result of the language forcing, er strongly encouraging, use of an unsuitable error reporting mechanism ("find some value in the range of the function's return type that isn't in the range of the function, and use it to indicate an error"). This wouldn't be an issue with exceptions or tuples / multivalue return like some languages allow.