-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use std::ptr::null_mut::<T>()
instead of 0 as *mut T
#202
Comments
This keeps coming up in our internal discussion occasionally, but there are some corner cases where they're not equivalent (I think in static initializers, I have to look up the original discussion for details). Meanwhile, you can do the following with
|
I also recall the two not being equivalent. I wonder if it was just because it wasn't a const fn at the time? Maybe it'd be viable now, but I'm not certain |
I checked last night, |
Hmm. Guess it wasn't that, lol |
One reason why they wouldn't be equivalent is static promotion. Also, being function calls they may be harder in general to analyze. Knowing that they are really null requires either interprocedural analysis (which may be intractable in general) or special-casing. Finally, these function calls shouldn't even normally appear in idiomatic Rust code. They are generally an artifact of partial initialization, redundant default-initialization (which should be folded away) or nullable pointers (which are better expressed as |
I think this should be re-considered, as |
FYI, this also makes |
c2rust current transpiles
NULL
pointers as0 as *mut T
, but it would be a bit cleaner and more rust-y to instead producestd::ptr::null_mut::<T>()
.The text was updated successfully, but these errors were encountered: