r/cpp • • Jul 13 '22

Why does Linus hate C++ ?

308 Upvotes

436 comments sorted by

View all comments

3

u/FreitasAlan Jul 13 '22

The features C++ offers are not useful to him. And that makes sense for an operating system.

For instance, templates are usually only useful for applications one level above. Doing what Eigen does with expression templates in C is almost impossible. On the other hand, templates are not useful to develop a driver and might even hide what's really happening at a lower level.

It doesn't mean it's bad for everyone. It's just not useful to him. Many other C++ features are optional and many C++ programmers don't use them either.

0

u/[deleted] Jul 13 '22

[deleted]

3

u/Wouter-van-Ooijen Jul 16 '22 edited Jul 16 '22

Of course I do. But to quote Dan Sasks (who also has a lot to say about this subject): "when you are arguing, you are loosing".

I use C++ templates all the time for very low level work. Example: a software (bit-banged) SPI driver. The GPIO pins used are template parameters. This way the inner loop (shifting the bits out and in) is as fast as when the GPIO pins were hard-coded.

For more on C++ and embedded: check my talks list. Most talks in it are C++, these links shows the ones that are tagged 'Embedded': https://wovo.github.io/ctl/?show_all&show_title&include_embedded

39

u/jcelerier ossia score Jul 13 '22

Other kernels don't have trouble with templates, e.g. they seem liberally used in SerenityOS, IncludeOS, etc.

Like, do you really think generic data structures like queues make no sense in a kernel?

11

u/Lumornys Jul 13 '22

Are there any problems with templates in kernel code? Templates are compile-time, so they should just work.

11

u/kammce WG21 | πŸ‡ΊπŸ‡² NB | Boost | Exceptions Jul 13 '22

You are correct, they are compile time constructs. I'm not sure how people come to the conclusion that templates have something about them that isn't suitable for things.

→ More replies (3)