module std.ffi
std.ffi — helpers for the C FFI (§16.1, D-1500..D-1510). Intrinsics: compiler/src/codegen/CGFfi.cpp.
str and the other managed types never cross the C boundary directly. Strings go through CString
(owned, NUL-terminated) and CStr.fromPtr; raw pointers *T / *var T are used inside unsafe with the
methods below; null<T>() and zeroed<T>() build the null pointer and an all-zero @c_layout value.
Example:
import c "stdlib.h" { atoi }
fn main() io {
let text = "42".toCString()
print("{unsafe { atoi(text.asPtr()) } + 1}")
}Output
43
Types
data CStr | Namespace of helpers for reading C strings. |
data CString | Owned, NUL-terminated copy of a str for passing to C (const char *). |
type List | type alias · std.ffi |
type str | type alias · std.ffi |
type T | type alias · std.ffi |
type var T | type alias · std.ffi |
Functions
null | The null pointer. |
sizeOf | sizeof(T) in bytes with C layout rules. |
zeroBytes | A list of n zero bytes |
zeroed | An all-zero value of a @c_layout type (C memset(&x, 0, sizeof x)); used to initialise out-parameters. |