Function Pointer cast
Function Pointer cast
Posted Feb 8, 2024 0:34 UTC (Thu) by milesrout (subscriber, #126894)In reply to: Function Pointer cast by tialaramex
Parent article: Defining the Rust 2024 edition
Then again I would say the same thing for the "undefined behaviour" that is dereferencing an invalid pointer. It's possible to define it perfectly well: you get the result of dereferencing it. And if that means that your system faults, then it faults. If it means you read garbage, you get garbage. But it doesn't give the compiler permission to compile out your later pointer validity checks.
Posted Feb 8, 2024 6:50 UTC (Thu)
by mb (subscriber, #50428)
[Link]
Yes. But that probably costs you most optimization opportunities and all parts of the code.
"Coding to the machine" and "getting what the hardware does" is impossible in real programs.
Function Pointer cast
You can have that behavior today by disabling optimization in C.
Not sure, if it's possible in Rust. Probably not. Rust is quite strict about assuming no-UB.