Skip to content

Instantly share code, notes, and snippets.

@ChristopherRabotin
Created February 21, 2019 23:57
Show Gist options
  • Save ChristopherRabotin/f12138245d3be9eb8d940113682bd042 to your computer and use it in GitHub Desktop.
Save ChristopherRabotin/f12138245d3be9eb8d940113682bd042 to your computer and use it in GitHub Desktop.
dangerous lack of lifetimes
#[no_mangle]
pub extern "C" fn det_c(m3x3: *const [[f64; 3]; 3]) -> f64 {
let m1 = unsafe { &*m3x3 };
((m1[0][0] * (m1[1][1] * m1[2][2] - m1[2][1] * m1[1][2]))
- (m1[0][1] * (m1[1][0] * m1[2][2] - m1[2][0] * m1[1][2]))
+ (m1[0][2] * (m1[1][0] * m1[2][1] - m1[2][0] * m1[1][1])))
}
#include <stdio.h>
#include <stdlib.h>
extern double det_c ( const double m1[3][3] );
int main() {
double m1[3][3] = {1, 2, 3, 0,5,6, 0,0,9};
printf("%f\n", det_c(m1));
return 0;
}
coffee:
rustc lib.rs --crate-type=cdylib -C opt-level=3 -C target-cpu=native
gcc main.c -o main.o -L. -llib -O3
LD_LIBRARY_PATH=. ./main.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment