3 ms·
Lol, part of me likes the effort taken just because, but the kernel devs _really_ do not want C++. One hint: "struct class" https://elixir.bootlin.com/linux/l
by monocasa 5y ago
Lol, part of me likes the effort taken just because, but the kernel devs _really_ do not want C++. One hint: "struct class"
https://elixir.bootlin.com/linux/latest/source/include/linux/device/class.h#L54 https://elixir.bootlin.com/linux/latest/source/include/linux...
- nly 5y agoWhat bothers me about that is that, because C doesn't have namespaces, it's already a terrible name for a struct. What if you want another "class" of thing? Call it device_class ffs
- deleted 5y ago[deleted]
- tuyiown 5y agoYou're dismissing the fact that the keyword collision really well might be intentional, the worst of it is that `/sys/class` siblings `bus` and `driver`, if their internal linux rep is actually in the `class.h` siblings, are called `struct bus_type` and `struct device_driver`
- leeter 5y agoI'd say it was extremely intentional given this: https://lwn.net/ml/linux-api/20180905165436.GA25206@kroah.com/ https://lwn.net/ml/linux-api/20180905165436.GA25206@kroah.co... And that's for a userspace header.
- jerrysievert 5y agoas long as nothing you're including includes that in c++, it shouldn't be an issue at the linker level, and thus not be an issue at all. at least in general - if it's something that can't handled by a c shim then you might have an issue.
- monocasa 5y agoIt's one of the most fundamental structures in the kernel. Pretty much all driver headers include it, if indirectly.
- Pinus 5y agoWasn't there a period recently — around 1995 or so — when the Linux kernel had to be compiled with a C++ compiler?
- mijoharas 5y agoWhy was that the case?
- monocasa 5y agoI don't think that's accurate. Maybe you're thinking of how it needs gcc extensions?
- cesarb 5y agoQuoting from http://vger.kernel.org/lkml/#s15-3 http://vger.kernel.org/lkml/#s15-3 : "In the dark old days, in the time that most of you hadn't even heard of the word "Linux", the kernel was once modified to be compiled under g++. That lasted for a few revisions. People complained about the performance drop. It turned out that compiling a piece of C code with g++ would give you worse code. It shouldn't have made a difference, but it did. Been there, done that."
- bluGill 5y agoI wonder if it is still true. C++ compilers have come a long way. (as have C compilers). C++ is 99% a superset of C, I'm not sure how much of that last is used in the kernel, so it might be too much effort, but C++ is in a few cases stricter than C in ways that compilers can use to optimize. Many C programs run faster when compiled in C++ these days. If there is a difference (either way) I'd expect it to be something you can measure, but not something you would notice in the real world on one computer. (though at google scale it probably shows up)
- steerablesafe 5y ago#define class Class #include <some_linux_header.h> #undef class /s