Init new repository
This commit is contained in:
33
tests/pointers.txt
Normal file
33
tests/pointers.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
import "libc";
|
||||
|
||||
main :: proc(): int {
|
||||
{
|
||||
arr: [100]int = {1, 2 ,3 ,4};
|
||||
p0 := addptr(arr, 1);
|
||||
assert(*p0 == 2);
|
||||
|
||||
p1 := addptr(p0, 1);
|
||||
assert(p1[0] == 3);
|
||||
}
|
||||
|
||||
{
|
||||
i: *int = :*int(1);
|
||||
if i {
|
||||
i = nil;
|
||||
assert(i == 0);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
token_count :: 20;
|
||||
tokens: [token_count]int;
|
||||
x: *int = addptr(tokens, 0);
|
||||
t: *int = addptr(tokens, 4);
|
||||
r1 := x && (t >= &tokens[0] && t < &tokens[token_count]);
|
||||
r2 := x && (t >= addptr(tokens, 0) && t < addptr(tokens, token_count));
|
||||
assert(r1 == true);
|
||||
assert(r2 == true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user