Add C to Rust example

This commit is contained in:
Alex Crichton
2015-04-19 10:28:20 -07:00
parent afbdb0cc41
commit 930924cdf5
4 changed files with 43 additions and 0 deletions

6
c-to-rust/src/lib.rs Normal file
View File

@@ -0,0 +1,6 @@
#![crate_type = "staticlib"]
#[no_mangle]
pub extern fn double_input(input: i32) -> i32 {
input * 2
}

11
c-to-rust/src/main.c Normal file
View File

@@ -0,0 +1,11 @@
#include <stdint.h>
#include <stdio.h>
extern int32_t double_input(int32_t input);
int main() {
int input = 4;
int output = double_input(input);
printf("%d * 2 = %d\n", input, output);
return 0;
}