blob: ef0ffa54a04b9e13fff87716dac9b65ecfd0b72d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
use std;
import std::ptr;
import std::unsafe;
type pair = {mutable fst: int, mutable snd: int};
#[test]
fn test() {
let p = {mutable fst: 10, mutable snd: 20};
let pptr: *mutable pair = ptr::addr_of(p);
let iptr: *mutable int = unsafe::reinterpret_cast(pptr);
assert (*iptr == 10);;
*iptr = 30;
assert (*iptr == 30);
assert (p.fst == 30);;
*pptr = {mutable fst: 50, mutable snd: 60};
assert (*iptr == 50);
assert (p.fst == 50);
assert (p.snd == 60);
}
|