r/cpp_questions • • Sep 13 '24

OPEN Why Linux community hates C++ so much?

It seems like they have an extreme disliking towards C++. Especially the kernel developers. Linus has even said he doesn't allow C++ in kernel just to keep C++ programmers away. Which sounds very weird because C++ seem to be used in all kinds of complicated systems, and they are fine.

175 Upvotes

192 comments sorted by

View all comments

Show parent comments

1

u/inscrutablemike Sep 13 '24

The things that come immediately to mind are vtables for dynamic method dispatch, memory allocators in the standard library, that kind of thing.

I know there are ways to write embedded code in C++, but once you start doing that.. is there any benefit over regular C? And does the benefit outweigh the inability to use so much of the standard C++ environment?

3

u/voidstarcpp Sep 14 '24

The things that come immediately to mind are vtables for dynamic method dispatch, memory allocators in the standard library, that kind of thing.

C and kernel APIs also have vtables, destructors, etc, you just have to fill them out yourself and infer from context or documentation what the pattern is rather than there existing a standard language mechanism for them.

The allocator behavior of the STL is arguably superior in that while C and C++ libraries both often use swappable allocation strategies, C++ can make these part of the type representation while C APIs usually defer these to runtime dispatch with function pointers.

but once you start doing that.. is there any benefit over regular C

C++ templates can bring more static knowledge and local context to generate data structures and functions faster than their C equivalents, unless you employ uncommon levels of C macros or autogen to bypass the language's limitations.

1

u/RedAlert2 Sep 14 '24 edited Sep 14 '24

A vtable is essentially just a struct of function pointers - you can have the same exact functionality in regular C. People use function pointers all the time in C.