News for hackers. Stuff that matters.
Re:Let rand = main as usize by comex on Thursday June 06, 2024 @02:51PM (#40601011)
It does not.

Oddly enough, it doesn't even allow it in unsafe code, not with a normal cast. You have to use transmute. I believe this is due to concerns about targets where function and data pointers have different representations.

https://rust-lang.github.io/unsafe-code-guidelines/layout/fu...

Re:Let rand = main as usize by duped on Thursday June 06, 2024 @04:30PM (#40602018)
I believe it has more to do with the fact that function pointers are effectively &'static T (static references) and references are forbidden from being null. But it's probably a bit of both.

In other words `0usize as fn ()` is insta-undefined behavior, and you can't have that in safe code.