|
|
Log in / Subscribe / Register

Beingessner: Rust's Unsafe Pointer Types Need An Overhaul

Beingessner: Rust's Unsafe Pointer Types Need An Overhaul

Posted Mar 21, 2022 22:40 UTC (Mon) by tialaramex (subscriber, #21167)
In reply to: Beingessner: Rust's Unsafe Pointer Types Need An Overhaul by wtarreau
Parent article: Beingessner: Rust's Unsafe Pointer Types Need An Overhaul

The sentence "IMHO that's what..." trails off without ever reaching any conclusion, but perhaps that's appropriate since whatever you were going for here, no they don't.

It's true that you can't alias variables with storage class register because you can't take their address, although this was a relatively late addition (K&R C does not have this rule), but there are no rules about aliasing volatile at all, neither allowing nor forbidding.

The standard says that register is merely a hint [which today your compiler almost certainly ignores], that it be a good idea to put this variable in a register and serves no other purpose despite the restriction.

Meanwhile volatile serves only one clear purpose, you can use it to perform explicit stores and loads from a memory address, likely because you are doing MMIO. This is tricky to get right but since C doesn't provide any intrinsics for this purpose it's the only way that's even a little bit portable. All other uses of volatile are platform specific (in the good cases) or just voodoo / cargo cult C, sprinkled on by people who are hoping maybe the bug goes away if they write volatile in more places.

> But if we could say "this never aliases anything" some constructs could be more easily optimized.

Which is why (safe) Rust gets to go very fast. But attempting to retro-fit this to a language like C is impractical.


The LWN site is currently under high scraper load, so comment display has been suppressed for anonymous users. If you are a human, you may read the comments by clicking the button below:

Note: you can avoid this step in the future by logging into your LWN account.


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