Rust Linking With C Library Functions

#[link(name = "c")]
extern "C" {
    fn scanf(format: *const u8, ...);
}

fn main() {
    let mut a = 0;
    let mut b = 0;
    unsafe {
        scanf("%d%d\0".as_ptr(), &mut a, &mut b);
    }
    println!("{}", a + b);
}

猜你喜欢

转载自www.cnblogs.com/JebediahKerman/p/Rust_Linking_With_C_Library_Functions.html