Logo

Programming-Idioms

History of Idiom 190 > diff from v9 to v10

Edit summary for version 10 by Oldboy:
New Python implementation by user [Oldboy]

Version 9

2021-08-16, 06:00:00

Version 10

2022-02-26, 20:59:04

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
Variables
a,n
Extra Keywords
C interoperability
Extra Keywords
C interoperability
Imports
from ctypes import *
Code
a = (c_int * 10)(*range(10))
n = 10
libc = cdll.LoadLibrary('/path/to/c_library')
libc.foo(c_void_p(a), c_int(n))