|
|
Subscribe / Log in / New account

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

Surely the solution to that problem is to fix miri so it corresponds to what actual machines do, rather than try to "fix" code that works fine on real machines but doesn't work on miri? The point of an abstract machine is to abstract away the irrelevant differences in the details between different concrete machines. But all actual targets for Rust have a single address space, at least for code (and most have a single address space for code and data). So there is no actual reason why this should be undefined.

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.


to post comments

Function Pointer cast

Posted Feb 8, 2024 6:50 UTC (Thu) by mb (subscriber, #50428) [Link]

> dereferencing an invalid pointer. It's possible to define it perfectly well

Yes. But that probably costs you most optimization opportunities and all parts of the code.
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.

"Coding to the machine" and "getting what the hardware does" is impossible in real programs.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds