From f87ad41f72ca4465a0c5b4ba9fd36a7b09e4d4f4 Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Mon, 24 Jun 2024 15:49:36 +0200 Subject: Initial commit Co-authored-by: Klaus Aehlig --- test/c-from-rust/main.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/c-from-rust/main.rs (limited to 'test/c-from-rust/main.rs') 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 = env::args().collect(); + match args[1].parse::() { + Ok(i) => println!("Absolute value of {} is {}",i, c_call(i)), + Err(..) => println!("Wrong argument {}",args[1]), + }; + +} -- cgit v1.2.3