diff options
author | Alberto Sartori <alberto.sartori@huawei.com> | 2024-06-24 15:49:36 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-06-24 15:49:36 +0200 |
commit | f87ad41f72ca4465a0c5b4ba9fd36a7b09e4d4f4 (patch) | |
tree | 24d4a3a5975df2046714c6bc114d5d050bdc61fc /test/c-from-rust/main.rs | |
download | rules-rust-f87ad41f72ca4465a0c5b4ba9fd36a7b09e4d4f4.tar.gz |
Initial commit
Co-authored-by: Klaus Aehlig <klaus.aehlig@huawei.com>
Diffstat (limited to 'test/c-from-rust/main.rs')
-rw-r--r-- | test/c-from-rust/main.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/c-from-rust/main.rs b/test/c-from-rust/main.rs new file mode 100644 index 0000000..961150a --- /dev/null +++ b/test/c-from-rust/main.rs @@ -0,0 +1,20 @@ +use std::env; + +extern "C" { + fn c_func(input: i32) -> i32; +} + +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]), + }; + +} |