Interfacing C Variadic Functions in Rust

Declaring the FFI Interface

Rust supports C Types and C as a Foreign Function Interface from the standard library. Interfacing with linked C code is fairly straightforward. C Variadic Functions are no different:

use std::os::raw::{c_char,c_int};
use std::ffi::CString;

extern "C" {
    fn printf(fmt: *const c_char, ...) -> c_int;
}

fn main() {
   let f = CString::new("%d %d").expect("CString::new failed");
   unsafe {
      printf(f.as_ptr(), 1, 2);
   }
}