Create an object at a given address: Difference between revisions

(Added FreeBASIC)
Line 512:
;; object
</lang>
 
=={{header|Rust}}==
In a real program, most if not all of the contents of main would all be in one `unsafe` block, however in this one each unsafe operation gets its own block to emphasize exactly which actions Rust considers unsafe.
<lang rust>use std::{mem,ptr};
 
fn main() {
let mut data: i32;
 
// Rust does not allow us to use uninitialized memory but the STL provides an `unsafe`
// function to override this protection.
unsafe {data = mem::uninitialized()}
 
// Construct a raw pointer (perfectly safe)
let address = &mut data as *mut _;
 
unsafe {ptr::write(address, 5)}
println!("{0:p}: {0}", &data);
 
unsafe {ptr::write(address, 6)}
println!("{0:p}: {0}", &data);
 
}</lang>
 
=={{header|Tcl}}==