so... jai :D
This commit is contained in:
35
examples/19-varargs.sx
Normal file
35
examples/19-varargs.sx
Normal file
@@ -0,0 +1,35 @@
|
||||
#import "modules/std.sx";
|
||||
|
||||
sum :: (args: ..s32) -> s32 {
|
||||
result := 0;
|
||||
for args {
|
||||
result = result + it;
|
||||
}
|
||||
result;
|
||||
}
|
||||
|
||||
print_all :: (args: ..s32) {
|
||||
for args {
|
||||
write(int_to_string(it));
|
||||
write(" ");
|
||||
}
|
||||
write("\n");
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
write(int_to_string(sum(10, 20, 30)));
|
||||
write("\n");
|
||||
|
||||
print_all(1, 2, 3, 4, 5);
|
||||
|
||||
arr : [3]s32 = .[10, 20, 30];
|
||||
write(int_to_string(sum(..arr)));
|
||||
write("\n");
|
||||
|
||||
for arr {
|
||||
write(int_to_string(it));
|
||||
write(" ");
|
||||
}
|
||||
write("\n");
|
||||
0;
|
||||
}
|
||||
Reference in New Issue
Block a user