rust/tests/ui/abi/extern/extern-call-indirect.rs
2024-04-17 15:08:08 -04:00

27 lines
500 B
Rust

//@ run-pass
#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_dbg_call(
cb: extern "C" fn(u64) -> u64,
data: u64,
) -> u64;
}
extern "C" fn cb(data: u64) -> u64 {
if data == 1 { data } else { fact(data - 1) * data }
}
fn fact(n: u64) -> u64 {
unsafe {
println!("n = {}", n);
rust_dbg_call(cb, n)
}
}
pub fn main() {
let result = fact(10);
println!("result = {}", result);
assert_eq!(result, 3628800);
}