Live data from Hacker News

C Questions and Answers

kukuruku.co

131–135 of 135 posts

Re: C Questions and Answers

#131
post #125

Earlier quoted context omitted.

> Algol is higher level than C. Sure, but it is also safer and already had helped implementing a few operating systems before C's authors could imagine coming up with C.

Right. My understanding of history is compiled Algol wasn't nearly as fast as compiled C, which was needed for operating systems and performance-critical code.

C fans like to re-invent history, just google for operating systems implemented in Algol variants and check their implementation dates.

Edit: Forgot to mention that up to the early 90's, C compilers generated pretty crappy code vs what any average Assembly coder could write. And was only relevant for those fortune to have UNIX at their company or university.

Re: C Questions and Answers

#132
post #127

Earlier quoted context omitted.

STL is not a problem in C land and fishy macros don't make it past code review in my book :-). I don't disagree on the usefulness of teasing your brain with these things once in a while. However, I think the best way to ensure you don't hit bugs caused by such things is to avoid the situation altogether.

It doesn't have to be a very fishy macro at all to be problematic. How about #define Sum(a,b) a+b This of course fails in any context where the precedence of '+' doesn't match your intent e.g. Sum(1,5) 7 becomes 1+5 7 Do you remember to always define your expression macros with parentheses? Any time you didn't do that, you have a bug.

> Do you remember to always define your expression macros with parentheses?

Yes - that's a necessary part of being idiomatic. Any macro that's defined without brackets sticks out like a sore thumb, and won't pass code review, even if it's (initially) used in a place where they wouldn't be necessary.

Re: C Questions and Answers

#133
post #127

Earlier quoted context omitted.

STL is not a problem in C land and fishy macros don't make it past code review in my book :-). I don't disagree on the usefulness of teasing your brain with these things once in a while. However, I think the best way to ensure you don't hit bugs caused by such things is to avoid the situation altogether.

It doesn't have to be a very fishy macro at all to be problematic. How about #define Sum(a,b) a+b This of course fails in any context where the precedence of '+' doesn't match your intent e.g. Sum(1,5) 7 becomes 1+5 7 Do you remember to always define your expression macros with parentheses? Any time you didn't do that, you have a bug.

> Do you remember to always define your expression macros with parentheses?

Oh, yes! No parentheses around elements of a macro definition is an obvious sound of trouble and looks very wrong on my retina.

I do agree, though, that if I somehow forgot to do that (tired? nervous?), that would be a bug that's difficult to spot. Point taken :). That's what code reviews are for, but there isn't always time or availability for one, sadly.

Re: C Questions and Answers

#134
post #131

Earlier quoted context omitted.

Right. My understanding of history is compiled Algol wasn't nearly as fast as compiled C, which was needed for operating systems and performance-critical code.

C fans like to re-invent history, just google for operating systems implemented in Algol variants and check their implementation dates. Edit: Forgot to mention that up to the early 90's, C compilers generated pretty crappy code vs what any average Assembly coder could write. And was only relevant for those fortune to have UNIX at their company or university.

Ok.

What do you think was the reason C took off while Algol use diminished? Was the growth of Unix a significant reason? Do you think C's adoption was misguided?

I think C's took off because C fit the sweet spot of ability to produce fast code while still being cross-platform and human-readable.

Re: C Questions and Answers

#135
post #131

Earlier quoted context omitted.

C fans like to re-invent history, just google for operating systems implemented in Algol variants and check their implementation dates. Edit: Forgot to mention that up to the early 90's, C compilers generated pretty crappy code vs what any average Assembly coder could write. And was only relevant for those fortune to have UNIX at their company or university.

Ok. What do you think was the reason C took off while Algol use diminished? Was the growth of Unix a significant reason? Do you think C's adoption was misguided? I think C's took off because C fit the sweet spot of ability to produce fast code while still being cross-platform and human-readable.

C took off because a few startups in the 80s used UNIX as the foundation of the workstations they were bringing into the market, like Sun for example.

As those workstations became a success in the US market, its use spread outside US and the need to have developers that could write software for them increased. This meant knowing C.

All the other operating systems at the time didn't offer C compilers. The few that did, it was just another language to choose from, most of the time only a subset of K&R C.

This is how the distinction between libc and POSIX APIs came to be. The original libc is mostly what could be implemented in other OSs without depending directly from the UNIX API semantics.

If the likes of Sun and SGI hadn't succeeded, most probably C would be a footnote just like Algol.

I have been writing software since 1986 and 1992 was the first time I cared to learn C, just to quickly ditch it for C++ on the year thereafter.

Post reply on HN