1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/compiler/tests/pointers_test.v

28 lines
419 B
V
Raw Normal View History

2019-11-11 18:43:22 +03:00
fn test_pointer_arithmetic() {
arr := [1,2,3,4]
unsafe {
mut parr := *int(arr.data)
2019-12-08 14:34:51 +03:00
parr++
2019-11-11 18:43:22 +03:00
assert 2 == *parr
2019-11-11 23:39:16 +03:00
parr++
assert 3 == *parr
assert *(parr + 1) == 4
2019-11-11 18:43:22 +03:00
}
}
fn test_multi_level_pointer_dereferencing() {
n := 100
pn := &n
ppn := &pn
unsafe {
mut pppn := &ppn
***pppn = 300
pppa := ***int(pppn)
assert 300 == ***pppa
}
assert n == 300 // updated by the unsafe pointer manipulation
}