about summary refs log tree commit diff
path: root/src/test/stdtest/ptr.rs
blob: a2242b1a06d73ea42b027ecf31d6a7bc4242f35e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import core::*;

use std;
import ptr;
import unsafe;

type pair = {mutable fst: int, mutable snd: int};

#[test]
fn test() unsafe {
    let p = {mutable fst: 10, mutable snd: 20};
    let pptr: *mutable pair = ptr::mut_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);
}