mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: multi-level pointers
This commit is contained in:

committed by
Alexander Medvednikov

parent
de5b4f0497
commit
0ab09a57f7
24
vlib/compiler/tests/pointers_test.v
Normal file
24
vlib/compiler/tests/pointers_test.v
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
fn test_pointer_arithmetic() {
|
||||
arr := [1,2,3,4]
|
||||
unsafe {
|
||||
mut parr := *int(arr.data)
|
||||
parr += 1
|
||||
assert 2 == *parr
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user