expression

C calling convention in a function pointer

The ABI describes how compiled callers and callees exchange arguments and results. The C ABI is target-specific; Rust’s default ABI is not a stable foreign interface. This local function-pointer call demonstrates the type without linking another library. Expected stdout (not executed): 1 0 Common mistake: Treating a Rust ABI function pointer as interchangeable with a C ABI pointer.

Formal Syntax & Structure

rust syntaxrust
extern "C" fn(c_int) -> c_int

Working Example

Example Snippetrust
#![deny(unsafe_op_in_unsafe_fn)]fn main() {    use std::ffi::c_int;    extern "C" fn classify(n: c_int) -> c_int { if n > 0 { 1 } else { 0 } }    let f: extern "C" fn(c_int) -> c_int = classify;    println!("{} {}", f(4), f(-2));}
Rust Reference