This commit is contained in:
agra
2026-02-10 22:47:43 +02:00
parent ef14144d49
commit 70435d3c85
11 changed files with 443 additions and 5 deletions

28
examples/26-pointers.sx Normal file
View File

@@ -0,0 +1,28 @@
#import "modules/std.sx";
Vec2 :: struct { x, y: f32; }
set_x :: (p: *Vec2, val: f32) {
p.x = val;
}
main :: () {
v := Vec2.{ 1.0, 2.0 };
print("before: {}\n", v);
set_x(&v, 99.0);
print("after: {}\n", v);
ptr := &v;
copy := ptr.*;
print("copy: {}\n", copy);
// null pointer
np : *Vec2 = null;
// many-pointer indexing
arr : [5]s32 = .[10, 20, 30, 40, 50];
mp : [*]s32 = &arr[0];
print("mp[0] = {}\n", mp[0]);
print("mp[2] = {}\n", mp[2]);
}