by Dylan16807 · 1mo ago · 0 comments
I can't find the quote you're talking about but I'll be surprised if it extends to assuming memory locations. If any pointer has to support touching any variable, even ones you never took the address of, that ruins so many basic and sensible optimizations.
Unless I'm misunderstanding, a normal computed goto would have an array of all the destinations. And hopefully it would compile to a delta multiply. But if you need to force it... maybe a compile time check that all the labels are delta bytes apart would let you do that math? I don't know, it's not part of the actual standard, it might be janky.
Did a plain old switch statement compile into something you didn't like?
Not that exact quote, but the spirit of it at 44:22.
https://youtu.be/uTxRF5ag27A?t=2662
Quote: "A zero-overhead principle. It basically says that if you have an abstraction, it should not cost anything compared to writing the equivalent code at a lower level."
Bjarne Stroustrup's criterion for language design is that C++ is an abstraction in itself over writing in assembly, and the language design should not get in the way by introducing overhead costs. C++ should allow the programmer to express their intent without losing performance relative to assembly, and it fails in this case due to undefined behavior.
So when the compiler doesn't let you implement your low-level code, it is a failure of the language and compiler relative to the design criteria of C++.
There are things you simply can't write in C. I think that's okay. But even if you don't think that's okay, it doesn't conflict with zero-overhead.
-
But also, when it comes to jumping by address to a goto you didn't check is at that address, I'm on the side of the compiler here. That's not how computed goto is supposed to work. You're supposed to use an address you can know is right by reading the code.