Created
February 21, 2019 23:57
-
-
Save ChristopherRabotin/f12138245d3be9eb8d940113682bd042 to your computer and use it in GitHub Desktop.
dangerous lack of lifetimes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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]))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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