2017-01-05 16:57:48 +08:00
|
|
|
const assert = @import("std").debug.assert;
|
2016-12-22 14:42:30 +08:00
|
|
|
|
2017-03-17 04:02:35 +08:00
|
|
|
test "intToPtrCast" {
|
2017-01-05 16:57:48 +08:00
|
|
|
const x = isize(13);
|
|
|
|
const y = (&u8)(x);
|
|
|
|
const z = usize(y);
|
|
|
|
assert(z == 13);
|
2016-12-22 14:42:30 +08:00
|
|
|
}
|
2017-02-01 02:38:04 +08:00
|
|
|
|
2017-03-17 04:02:35 +08:00
|
|
|
test "numLitIntToPtrCast" {
|
2017-02-01 02:38:04 +08:00
|
|
|
const vga_mem = (&u16)(0xB8000);
|
|
|
|
assert(usize(vga_mem) == 0xB8000);
|
|
|
|
}
|
2017-03-15 09:38:27 +08:00
|
|
|
|
2017-03-17 04:02:35 +08:00
|
|
|
test "pointerReinterpretConstFloatToInt" {
|
2017-03-15 09:38:27 +08:00
|
|
|
const float: f64 = 5.99999999999994648725e-01;
|
|
|
|
const float_ptr = &float;
|
|
|
|
const int_ptr = (&i32)(float_ptr);
|
|
|
|
const int_val = *int_ptr;
|
|
|
|
assert(int_val == 858993411);
|
|
|
|
}
|