Skip to content

Instantly share code, notes, and snippets.

Created August 3, 2017 16:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a5552e15e41f136753ac723d18e1d7fd to your computer and use it in GitHub Desktop.
Save anonymous/a5552e15e41f136753ac723d18e1d7fd to your computer and use it in GitHub Desktop.
Rust code shared from the playground
extern crate libc;
use libc::c_char;
use std::ffi::CString;
fn gimme_cstring_pointer() -> *const c_char {
CString::new("hi").unwrap().as_ptr()
}
fn gimme_cstring() -> CString {
CString::new("hi").unwrap()
}
fn main() {
let c_string = gimme_cstring().as_ptr();
println!("Address {:?}", c_string.as_ptr());
unsafe {
println!("Content {:?}", *c_string.as_ptr());
}
let c_string_pointer = gimme_cstring_pointer();
println!("Address {:?}", c_string_pointer);
unsafe {
println!("Content {:?}", *c_string_pointer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment