Logo

Programming-Idioms

History of Idiom 190 > diff from v6 to v7

Edit summary for version 7 by Plecra:
New Rust implementation by user [Plecra]

Version 6

2019-10-07, 04:47:35

Version 7

2020-07-15, 17:16:39

Idiom #190 Call an external C function

Declare an external C function with the prototype

void foo(double *a, int n);

and call it, passing an array (or a list) of size 10 to a and 10 to n.

Use only standard features of your language.

Idiom #190 Call an external C function

Declare an external C function with the prototype

void foo(double *a, int n);

and call it, passing an array (or a list) of size 10 to a and 10 to n.

Use only standard features of your language.

Variables
a,n
Extra Keywords
C interoperability
Extra Keywords
C interoperability
Code
extern "C" {
    /// # Safety
    ///
    /// `a` must point to an array of at least size 10
    fn foo(a: *mut libc::c_double, n: libc::c_int);
}

let mut a = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0];
let n = 10;
unsafe {
    foo(a.as_mut_ptr(), n);
}