Created
August 3, 2017 16:20
-
-
Save anonymous/a5552e15e41f136753ac723d18e1d7fd to your computer and use it in GitHub Desktop.
Rust code shared from the playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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