blob: ff27dd7957c7a13b850a4045e5c061cb23b2a57c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
use std::env;
// declaration of the function implemented in the C library
extern "C" {
fn c_func(input: i32) -> i32;
}
// wrapper to call the C function
fn c_call(i: i32) -> i32 {
unsafe {
return c_func(i);
}
}
fn main() {
let args: Vec<String> = env::args().collect();
match args[1].parse::<i32>() {
Ok(i) => println!("Absolute value of {} is {}", i, c_call(i)),
Err(..) => println!("Wrong argument {}", args[1]),
};
}
|