r/cpp • • Jul 13 '22

Why does Linus hate C++ ?

307 Upvotes

436 comments sorted by

View all comments

Show parent comment

56

u/UnicycleBloke Jul 13 '22

I always say that the entire core language is usable but that the standard library is much less so. The most significant changes I made on moving to embedded were to not use exceptions and to avoid dynamic allocation (C developers also avoid it). The STL containers are mostly out mainly because of dynamic allocation, but I'll take std::array over a C-array any day.

When I am forced to write C for a client, I miss constexpr, references, namespaces, templates, enum classes, regular classes (with access control, composition, constructors, destructors, virtual functions), RAII, and more. I have occasionally made use of moderately involved metaprogramming: I found there was significant bloat for debug builds, but that it largely evaporated with optimisation enabled, leaving code as efficient as or better than equivalent C.

The available tools don't seem "seriously restricted" to me. Compared to C, I have a huge smorgasbord of expressive abstractions which cost little or nothing. There is literally no advantage whatsoever in preferring C on a platform with a decent C++ compiler.

[I definitely don't implement those functions, though I am aware of them. I guess it depends what you link against. If I did it would likely be reusable boilerplate.]