vxx2 / vlib / v / checker / tests / pointer_ops.vv
32 lines · 30 sloc · 368 bytes · 474033c05554f377b50bc8884aae28f3c0334177
Raw
1struct Foo {}
2
3// void* arithmetic is not allowed in MSVC, so ban it
4fn test_voidptr() {
5 unsafe {
6 mut p := voidptr(u64(0))
7 _ = p + 1
8 p++
9 p += 3
10 _ = p - 1
11 p--
12 p -= 3
13 _ = p[3]
14 mut foo := &Foo{}
15 foo % 3
16 }
17}
18
19fn test_nil() {
20 unsafe {
21 mut p := nil
22 _ = p + 1
23 p++
24 p += 3
25 _ = p - 1
26 p--
27 p -= 3
28 _ = p[3]
29 mut foo := &Foo{}
30 foo % 3
31 }
32}
33