OxL Справочник OxL
РусскийEnglish

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:

oxl✓ проверяется в CI
import c "stdlib.h" { atoi }

fn main() io {
  let text = "42".toCString()
  print("{unsafe { atoi(text.asPtr()) } + 1}")
}
Вывод
43

Типы

data CStrNamespace of helpers for reading C strings.
data CStringOwned, NUL-terminated copy of a str for passing to C (const char *).
type Listпсевдоним · std.ffi
type strпсевдоним · std.ffi
type Tпсевдоним · std.ffi
type var Tпсевдоним · std.ffi

Функции

nullThe null pointer.
sizeOfsizeof(T) in bytes with C layout rules.
zeroBytesA list of n zero bytes
zeroedAn all-zero value of a @c_layout type (C memset(&x, 0, sizeof x)); used to initialise out-parameters.

См. также