-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Need documentations on pointer casts #17481
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
Comments
let addrp: *const libc::sockaddr = &storage as *const _ as *const _; the first
static X: u8 = 128;
static Y: *const i8 = &X as *const _ as *const _;
fn main() {
assert_eq!(unsafe { *Y }, -128);
} |
@mahkoh Thank you so much for your reply. However, you would be too busy if you had to answer to every single Rust programmer writing an FFI code involving I indeed see the underscore symbol introduces
However the language reference mentions to the underscore symbol only in the section on the |
fix: pattern completions in let-stmt fix rust-lang#17480. We can write `let S { a, b } = s;` or `let Some(x) = a else {}`, so it is reasonable to allow pattern completions in `LetStmt`.
This is how the language reference describes the cast experssions:
However, grepping for
as .* as
insrc/libnative
, for example, finds many instances of cast expressions which deviate from the above description. For exampleconst_cast
in C++ but is not described anywhere.As for the above particular instance, the combination of
ref_slice()
andas_ptr()
seems "more standard-compliant" to me and makes me wonder if the above special casts are really essential to Rust (ref_slice()
is built on top of the magical intrinsictransmute()
).The text was updated successfully, but these errors were encountered: