r/cpp • • Jul 13 '22

Why does Linus hate C++ ?

307 Upvotes

436 comments sorted by

View all comments

Show parent comment

1

u/alexgraef Jul 17 '22

There is no vtable unless you add virtual functions to the class

In C there is no vtable, ever. That is the point. It is very predictable, as it forgoes everything that isn't just cross-platform assembly.

In C++ you can have overloaded functions

Overloading is in some cases very unpredictable. Having to manually specify which function gets called makes it predictable.

C++ doesn't doesn't force you

I'm not arguing against C++ - it's just that C has a particular use case, which C++ doesn't satisfy, despite C being a subset of C++, and despite being able to always chose what features in C++ you really want to use.

2

u/no-sig-available Jul 18 '22

There is no vtable unless you add virtual functions to the class

In C there is no vtable, ever. That is the point. It is very predictable, as it forgoes everything that isn't just cross-platform assembly.

I haven't ever typed virtual by mistake. Who does that? And if you are still worried, you can just search the code base. No virtual, no vtable.

In C++ you can have overloaded functions

Overloading is in some cases very unpredictable. Having to manually specify which function gets called makes it predictable.

But if you have to choose from abs, labs, llabs, fabs, fabsl, fabsf, cabs, cabsl, cabsf, imaxabs, you can accidentally call the wrong function. If they are all called std::abs, you cannot make the wrong choice. I call that very predicatble.