Skip to content

Feature request: Use more idiomatic ptr null pointer APIs instead of hardcoded 0s #620

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

Closed
64kramsystem opened this issue Aug 16, 2022 · 1 comment
Labels
wontfix This will not be worked on

Comments

@64kramsystem
Copy link
Contributor

64kramsystem commented Aug 16, 2022

When c2rust transpiles null pointers, it uses hardcoded 0s converted to the dedicated types, eg.:

static mut demoptr: *mut i8 = 0 as *const i8 as *mut i8;

this is technically correct, however, using the dedicated ptr APIs leads to more readable and idiomatic code:

static mut demoptr: *mut u8 = ptr::null_mut();

(this applies only to Sized types, though)

@kkysen
Copy link
Contributor

kkysen commented Aug 16, 2022

This was already discussed in #202. There can be some subtle other differences between the two (#202 (comment)), and when refactoring, both 0 as *mut _ and ptr::null_mut() would be removed in favor of non-raw pointer APIs, so the difference usually doesn't end up mattering so much. Previous, this change could be done with the refactorer (c2rust refactor) (#202 (comment)), but that's now been deprecated as we're working on a more thorough way to lift unsafe Rust into safe Rust.

@kkysen kkysen closed this as completed Aug 16, 2022
@kkysen kkysen closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2022
@kkysen kkysen added the wontfix This will not be worked on label Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants