Skip to content

Instantly share code, notes, and snippets.

@mzumi
Last active November 2, 2016 11:50
Show Gist options
  • Save mzumi/b1512cfd084ac0e0cd3629c1a2621795 to your computer and use it in GitHub Desktop.
Save mzumi/b1512cfd084ac0e0cd3629c1a2621795 to your computer and use it in GitHub Desktop.
#![feature(libc)]
extern crate libc;
use libc::*;
use std::ffi::{CStr, CString};
#[repr(C)]
pub struct SampleStruct {
i: i32,
b: bool,
s: *const c_char
}
#[no_mangle]
pub extern fn create_sample_struct(s: *mut SampleStruct) {
unsafe {
(*s).i = 100;
(*s).b = false;
(*s).s = CString::new("hello").unwrap().into_raw();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment