|
|
Subscribe / Log in / New account

Rust vs. C

Rust vs. C

Posted Oct 18, 2024 6:13 UTC (Fri) by mb (subscriber, #50428)
In reply to: Rust vs. C by blackfire
Parent article: Smart pointers for the kernel

>except `unsafe`, but if you use it to violate the "aliased xor mutable" rule, it's insta-UB anyway)

Hm, are you sure that just having two aliasing nonconst raw pointers is insta-UB?
That doesn't look right to me.


to post comments

Rust vs. C

Posted Oct 18, 2024 7:56 UTC (Fri) by blackfire (guest, #92738) [Link]

> Hm, are you sure that just having two aliasing nonconst raw pointers is insta-UB?
> That doesn't look right to me.

Having multiple raw pointers (const or not) is fine, having multiple mut references (or one mut and 1+ const) is UB, even without dereferencing any of them.

(this is made mildly more complex by stacked borrows but that's the gist and honestly I don't claim to fully understand the intricacies of the model, but you do have to watch out for UB any time you make a reference from a raw pointer)


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