Live data from Hacker News

The Problem with C (2020)

cor3ntin.github.io

41–50 of 177 posts

Re: The Problem with C (2020)

#41
post #21

Earlier quoted context omitted.

Do you have a concrete example of some operation where avoiding undefined behavior is impossible?

It's not a particular operation that is the problem, it's writing a whole real-life program with no UB that is the problem. Even so, one example in C++ where it's almost impossible to avoid UB is treating a piece of memory as both a struct and raw bytes with guarantees of no copying. This comes up a lot in network packet processing.

Right, yeah I can see how the "no copying" requirement is a tough one. Thanks.

Re: The Problem with C (2020)

#42
post #25

C is the glue interface that connects all the different languages together. I wouldn't want to see anything new added to the language that complicates this lingua franca. I liked C in the 80s, 90s and 2000s. It was a neat and simple language, but that changed as compilers got more aggressive with their optimizations and exposed just how complicated and unintuitive the spec actually is (and the impossibility of avoidi…

I'm still a proponent of C as portable assembly, and any sort of optimizations / UB that gets used resulting in warning messages that can improve the source code of the program rather than the one time artifacts the compiler produces.

I'm curious, are you working on such a C compiler?

For the two decades I've used C, I've not had a compiler that resembles "portable assembly." The unoptimized code they generate is extremely naive and far removed from anything an assembly programmer would write, easily resulting in many times more instructions than a simple & straightforward assembly implementation. As one might expect, the performance of such code is atrocious.

With gcc and clang, optimizations are absolutely mandatory if you want compilers to generate anything resembling good assembly. And it is still an uphill fight to avoid silly code. Just last week I scratched my head because gcc insisted on recreating a constant that is already there in a register, in that very same register it is recreating it in [1]. You could force it to keep the value in a register by creating a top level variable and use the asm("register") extension, but that just resulted in gcc making copies of that value into other registers.

Also worth pointing out that there's a lot of stuff in assembly that you cannot express in C directly. You want a rotate instead of two shifts and OR? You absolutely have to have an optimizing compiler, because rotate does not exist in C. Want to shift and test carry? No, that is not possible in C. Compiler extensions give you access to some things (e.g. popcnt) but the vast majority of assembly is only achievable indirectly by assuming the compiler can optimize your code and figure out what instruction you want. Also those extensions hardly make it portable..

I also think the vast majority of C code I see looks very different from assembly; it is written under the assumption of an optimizing compiler, which converts idiomatic C to somewhat idiomatic assembly.

[1] http://fpaste.dy.fi/bRq/disp

Re: The Problem with C (2020)

#43

C is the glue interface that connects all the different languages together. I wouldn't want to see anything new added to the language that complicates this lingua franca. I liked C in the 80s, 90s and 2000s. It was a neat and simple language, but that changed as compilers got more aggressive with their optimizations and exposed just how complicated and unintuitive the spec actually is (and the impossibility of avoidi…

What makes you think Rust and Zig will not suffer the same issue given enough time?

Computer science is less than a century old. There's no reason to think we know enough to design perfect languages yet. But with an additional 30 years of hindsight, we can make somewhat better languages now, and we should.

Re: The Problem with C (2020)

#45

C is the glue interface that connects all the different languages together. I wouldn't want to see anything new added to the language that complicates this lingua franca. I liked C in the 80s, 90s and 2000s. It was a neat and simple language, but that changed as compilers got more aggressive with their optimizations and exposed just how complicated and unintuitive the spec actually is (and the impossibility of avoidi…

Indeed, and rust, zig, fortran, and julia don't have the problems with c that c++ does, so is it a problem with c or with c++ that the author is actually talking about?

Honestly, this is a C++ problem and the article should be named "The Problem with C++". Like you said, other languages do not have these problems to the same extent.

Re: The Problem with C (2020)

#46
post #21

Earlier quoted context omitted.

Do you have a concrete example of some operation where avoiding undefined behavior is impossible?

It's not a particular operation that is the problem, it's writing a whole real-life program with no UB that is the problem. Even so, one example in C++ where it's almost impossible to avoid UB is treating a piece of memory as both a struct and raw bytes with guarantees of no copying. This comes up a lot in network packet processing.

This makes me wonder how protobufs manages to implement zero-copy structs.

Re: The Problem with C (2020)

#47
> > There Are No C Conferences. Maybe that’s why the C++ committee is now over 10 times the size of the C committee.

I have this controversial thought: C people understood one thing before everyone else (including the creators of C++, Rust, and any other language), and is this:

“Perfection is Achieved Not When There Is Nothing More to Add, But When There Is Nothing Left to Take Away” -- Antoine de Saint-Exupery.

Super-bloated languages that keep adding features every month/year are far from perfection.

Now bring it on!

Note: I love both C and C++. I prefer C because it's simpler (I write firmware for a living). Sometimes I use C++ with simple classes and I might throw in a template or two if I am in a good day. Of course my classes are for my use only: don't try to copy/move them!! I won't chase every little nitpick of deleting and overriding every operator/constructor!! And the further I might go is implementing a Singleton.

Re: The Problem with C (2020)

#48
post #32

C++ is an overloaded language whose complexity seems to be growing with each revision. Heck, I remember Bjarne Stroustrup even semi-lamenting it in one of the interviews. I don't understand why this is a C problem, whose syntax and definitions have been relatively stable for the last 3 decades. Author has gripes with C++ 'universality' IMHO but just piling it on C.

> I don't understand why this is a C problem

Because it isn't a C problem. C has been basically stable for decades.

C++ is free to overload itself by piling ever more stuff onto itself, but any problems this language has, are not problems of C, or problems C needs to fix.

Re: The Problem with C (2020)

#49
post #11

Earlier quoted context omitted.

C23 is considering following C++ footsteps and repurpose auto as well.

I hope they don't, at the very least we can afford to choose a new keyword. Even if auto was infrequently used, it's no good to silently change the meaning of existing valid programs.

It is part of N2891

"Type inference for variable definitions and function returns"

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p230...

Enjoy some of the other proposals,

"Basic lambdas for C"

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p230...

"Improve type generic programming"

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p230...

"Type-generic lambdas"

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p230...

"Revise spelling of keywords"

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p231...

"Make false and true first-class language features"

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p231...

Naturally at this point one could ask why not just use C++ instead, well that is what happens when a language group is so firmly against moving upwards, but still wants the features on their language.

Naturally missing from the list are any kind of improvements to string or arrays alternatives, as usual.

Re: The Problem with C (2020)

#50
post #47

> > There Are No C Conferences. Maybe that’s why the C++ committee is now over 10 times the size of the C committee. I have this controversial thought: C people understood one thing before everyone else (including the creators of C++, Rust, and any other language), and is this: “Perfection is Achieved Not When There Is Nothing More to Add, But When There Is Nothing Left to Take Away” -- Antoine de Saint-Exupery. Supe…

I guess you haven't kept up to date with ISO C work.
Post reply on HN