Created
April 20, 2019 03:34
-
-
Save rust-play/b70c21240c9bc9fb5eadcc083852c276 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern fn foo() {} | |
extern "C" { | |
// This doesn't cast `Some(foo)` to the correct type | |
fn printf(fmt: *const u8, ...); | |
// This works correctly | |
//fn printf(fmt: *const u8, _: Option<extern fn()>); | |
} | |
fn main() { | |
unsafe { | |
// ERROR: printf(b"foo:%p\n\x00".as_ptr(), foo); | |
printf(b"foo:%p\n\x00".as_ptr(), foo as extern fn()); | |
printf(b"foo:%p\n\x00".as_ptr(), Some(foo)); | |
printf(b"foo:%p\n\x00".as_ptr(), Some(foo as extern fn())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment