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

2

u/tyler1128 Sep 14 '24

Yeah, you can always manually implement anything, the big difference is that you have full control. Just throw a function pointer into a struct in C and you have basically the same thing as a class, just less conveniently. You can write your own vtable which is how inheritence works in C++. Just look at GDK, they made a full object oriented system with features beyond what C++ supports in C. It also is horrible to work with through C.

1

u/[deleted] Sep 14 '24

Won't throwing in a function pointer in a struct make it a cpp struct equivalent? Class members are private by nature right? Or are members of a struct private in C? I thought they were public.

1

u/masorick Sep 15 '24

There are ways around that.

Put a few function pointers in a struct to make a vtable. Put a pointer to that vtable (and nothing else) inside another struct and you got an interface.

Then anyone can implement your interface by embedding the interface struct inside their own struct (if it’s the first member, they can even cast pointers back and forth between the interface and the implementation). But as the one who created the interface, you have no idea what’s in the implementation, you only have access to the function pointers.

2

u/[deleted] Sep 16 '24

Oh yeah! This is actually neat! I'll try this