4 ms·
C has not really been close to the metal for a long time. The C abstract machine is actually very complicated, especially the rules around undefined behavior. J
by roca 7y ago
C has not really been close to the metal for a long time. The C abstract machine is actually very complicated, especially the rules around undefined behavior. John Regehr's blog explains this well, e.g. https://blog.regehr.org/archives/213 https://blog.regehr.org/archives/213. It's easy to write code that looks like it will compile to something simple and obvious but that current compilers will turn into code that does something else entirely, or worse, current compilers compile as you expect but future compilers will mangle.
If you want to be reliably close to the metal, I think the best options are either to actually write assembly, or use a language with a simpler abstract machine (preferably, no undefined behavior), that statically compiles to code that maps closely to what you wrote, and lets you generate "idiomatic machine code" (e.g. unboxed integers). Safe Rust fits the bill, but there are probably other more obscure options.