On this page
  1. extern_C
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

extern_C

Prev: `CString` | Up: ffi | Next: ownership_and_internals
Rel: ffi, rust/builtins
Ref: Rust std — extern_C
Tags: #public #prog #rust #stdlib #ffi #tier/specialized


Signature & Overview

#[unsafe(no_mangle)] pub extern "C" fn add(a: i32, b: i32) -> i32

Exports or imports functions using the platform C calling convention with #[repr(C)] structs.

Notes & Pitfalls

Example

#[no_mangle]
pub extern "C" fn add_from_rust(a: i32, b: i32) -> i32 {
    a.wrapping_add(b)
}

fn main() {
    assert_eq!(add_from_rust(20, 22), 42);
}

Linked from

Related notes