5 ms·
Also a demonstration of how much work other compilers do for you behind the scenes.
by asplake 2y ago
Also a demonstration of how much work other compilers do for you behind the scenes.
- Groxx 2y agoEhhh... not much more so than how much `npm install` hides. These macros are part of a gigantic tower of absurdity that costs many, many times more than they need to, but we use them because dev time is more valuable than CPU time.
- rerdavies 2y agoDev time spent waiting for compiles is way more expensive than CPU time.
- jonathrg 2y agoA compiler for a language with generic types will definitely do less work to implement generic min/max than the C preprocessor has to do in order to perform all the text substitutions generated by these macros.
- asplake 2y agoOh totally! It has the information to do it both properly and efficiently.
- usr1106 2y agoOr a demonstration about the poor state of programming languages in 2024. Of course there are others than C. But not many suitable for writing a kernel. And no obvious choice for what Linux could do today. Of course they are starting with Rust, but nobody can predict when that will make the last C macro unnecessary. Unless your prediction is never...
- pjmlp 2y agoPlenty of kernels have been written in other languages, naturally UNIX/POSIX folks can hardly think of something else. Even Linus accepting Rust is kind of interesting, because his C++ rants also apply to plenty of Rust code bases.
- gary_0 2y agoDoesn't Rust's `no_std` make it easy to throw out idioms you can't use (or don't like) and just keep the syntax and most of the tooling? I recall that one of Linus's preconditions for inclusion was that Rust's default of panic!ing on allocation failures had to be overrideable. Whereas C++ tends to make you eat the whole enchilada.
- pjmlp 2y agoC++ compilers have similar options, e.g. VC++ has /kernel, and there is the freestanding standard as well. Also see Embedded C++ as used by macOS IO Kit, which thankfully there isn't a Linus at Apple. Regarding Rust, no_std, doesn't change the npm like dependencies, macro festival (with two ways of doing all kinds of stuff), abstraction party with type driven development, the compile times.
- tialaramex 2y agoThe C++ "freestanding" even when the current round of work is completed, is nowhere close to Rust's core. Partly this is because Rust thought about this earlier, and partly it's because of the relationship between C++ and the allocator, having operators for a feature which might not even exist on your target, awkward.