Skip to content

Commit

Permalink
Added integer addition example
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Feb 26, 2022
1 parent 07e1fe9 commit fa81f98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions go/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ package main
#include "./rustlib.h"
*/
import "C"
import "fmt"

func main() {
// 1 - Hello
C.hello()

// 2 - Addition
x := C.uint32_t(10)
y := C.uint32_t(100)
add := uint(C.addition(x, y))
fmt.Printf("Addition=%d\r\n", add)
}
5 changes: 4 additions & 1 deletion go/cmd/rustlib.h
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
extern int hello();
#include <stdint.h>

extern void hello();
extern uint32_t addition(uint32_t, uint32_t);
5 changes: 5 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
pub extern "C" fn hello() {
println!("Hello World in Rust");
}

#[no_mangle]
pub extern "C" fn addition(x: u32, y: u32) -> u32 {
x + y
}

0 comments on commit fa81f98

Please sign in to comment.