r/cpp • • Jul 13 '22

Why does Linus hate C++ ?

308 Upvotes

436 comments sorted by

View all comments

Show parent comments

1

u/simulacrasimulation_ Jul 13 '22

Aside from C not being object-oriented like C++, what are some of the more nuanced differences as to why one would choose C over C++ (and vice-versa)?

12

u/alexgraef Jul 13 '22

Not sure if that answers your question - but C is basically just cross-platform assembly. That was the original intention, and to this date, what you can do is mostly pointer manipulation/arithmetic. Structs for example are just a fancy way for doing pointer arithmetic.

This all means that C code is very deterministic, regarding behavior as well as timing. Well suited if you want as little abstraction from the hardware as possible.

12

u/no-sig-available Jul 13 '22

Structs for example are just a fancy way for doing pointer arithmetic.

This all means that C code is very deterministic, regarding behavior as well as timing. Well suited if you want as little abstraction from the hardware as possible.

And C++ also has structs. :-)

So you can use the "little abstraction" when you build the hardware interface layer. Then you can add more abstractions when you build the next layer. You don't have to be close to the hardware all the way, all the time.

1

u/alexgraef Jul 15 '22

That was not the point. As C is a subset of C++, you can generally do everything in C++ that C would allow you.

However, C does not implement vtables for structs. And classes aren't just "a fancy way for doing pointer arithmetic". There's a lot more going on in the background.

→ More replies (3)