5 ms·
Linux only compiles with at least semi-recent compilers. The minimum version for GCC even has been bumped not too long ago. They certainly are able to handle C9
by temac 7y ago
Linux only compiles with at least semi-recent compilers. The minimum version for GCC even has been bumped not too long ago. They certainly are able to handle C99 style declarations. Why Linus hate them, I don't know, probably he could be able to formulate some pseudo justifications when in reality it is just what he is used to.
The only thing I could find quickly was from 2005: https://lkml.org/lkml/2005/12/13/223 https://lkml.org/lkml/2005/12/13/223
Maybe it made sense in 2005, but 14 years later this might not be that much important anymore. To be honest I'm radically against the opinion that "Putting variables in the middle of code only improves readability when you have messy code", but I kind of understand where it comes from, with an hardcore old-school C mindset. With experience with more modern programming languages and considering code like more abstract level object instead of low level immediate imperative instructions, not putting declarations before the variable are needed makes sense. This is more in line with how modern compiler work AND more importantly with what we need to do to reason on code (not surprising because part of the reasoning is the same for a modern compiler and for us), and I suspect that this actually leads to less programming errors, including the silly ones we saw here.
- ncmncm 7y agoIt is of a piece with forbidding link-compatible C++ components. Destructors prevent far more mistakes than they cause, and templates, used correctly, are much more specific and less error-prone than macros.
- kevin_thibedeau 7y agoC++ is broken without exceptions. Exceptions aren't ever going to enter the kernel even if you tried to hide them behind a C ABI.
- nickpsecurity 7y agoThe folks behind the Pistachio microkernel said they used C++: https://github.com/l4ka/pistachio https://github.com/l4ka/pistachio I don't know if it has exceptions or an unusual style since I don't know C++. It is written by CompSci researchers which usually means a different style. Just throwing it out there for anyone considering C++ in kernels since the L4 kernels were all really fast and lean.
- kevin_thibedeau 7y agoAnd Google merrily uses C++ with exceptions disabled. That doesn't make it right when the shit hits the fan. "Works most of the time" is not acceptable in an OS.
- nickpsecurity 7y agoYour statement equates not using exceptions with no error handling at all. Are exceptions the only way C++ can handle errors? Or can it do things like return codes used in C or advanced constructs via its metaprogramming?
- tomjakubowski 7y agoYou can use error codes or, better, a Result<T, E> template in C++, but throwing an exception is the only sane way to signal an error from a C++ constructor that I know of. The alternatives are awkward: you either stick an error code on the struct, which the caller can check after construction, or write an error code to the caller through an out parameter. In either case, the class implementation now must be concerned with handling objects in some partly-initialized, "error" state.
- ncmncm 7y agoError handling without exceptions tends to 3x to 5x as much raw code, with corresponding numbers of errors and poorly-exercised paths. Exception paths rely mostly on destructors which are otherwise well-tested in normal operation.
- kevingadd 7y agoWould you seriously argue that "works most of the time" does not describe C? Or are you just saying that accepting it for another language is not okay, and anything new allowed into the kernel needs to be perfect instead of just better than C?