1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/v/tests/unsafe_test.v
2020-08-04 00:29:10 +02:00

46 lines
493 B
V

fn test_ptr_assign() {
v := [int(5), 6, 77, 1]
mut p := &v[0]
unsafe {
(*p)++
}
unsafe {
p++
} // p now points to v[1]
unsafe {
(*p) += 2
}
unsafe {
p += 2
} // p now points to v[3]
unsafe {
*p = 31
}
assert v[0] == 6
assert v[1] == 8
assert v[2] == 77
assert v[3] == 31
}
fn test_ptr_infix() {
v := 4
mut q := unsafe {&v - 1}
q = unsafe {q + 3}
_ := q
_ := v
}
struct S1 {
}
[unsafe_fn]
fn (s S1) f() {
}
fn test_funcs() {
s := S1{}
unsafe {
s.f()
}
}