diff options
| author | 2022-08-06 16:11:26 +0200 | |
|---|---|---|
| committer | 2022-08-06 16:11:26 +0200 | |
| commit | 0c6330ce7ee50c1fa241793588fa83a3c00bc3c1 (patch) | |
| tree | 3c8c42804a8056a61b267d690a13688d6580630a /bootstrap/test.cff | |
| parent | c53e17496d97a2fb638544cee414de97d81770fc (diff) | |
inferred length array init
Diffstat (limited to 'bootstrap/test.cff')
| -rw-r--r-- | bootstrap/test.cff | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/bootstrap/test.cff b/bootstrap/test.cff index 7a6b7ce..be6cb95 100644 --- a/bootstrap/test.cff +++ b/bootstrap/test.cff @@ -10,8 +10,9 @@ enum Color { Red, Green, Blue } +defmacro arraylength(ary) [ (sizeof(ary)/sizeof(ary[0])) ] defmacro each(i, x, arr, ...body) [ - for let i = 0; i < sizeof(arr)/sizeof(arr[0]); ++i { + for let i = 0; i < arraylength(arr); ++i { let x = arr[i]; { body } } @@ -58,8 +59,8 @@ extern fn main (argc int, argv **u8) int { x->zero(); printf("mag = %g\n", (&x)->mag()); - let is [10]int = { [4] = 1, 2, [1 - 1] = 3 }; - isort(is, 10); + let is []int = { [4] = 1, 2, [1 - 1] = 3 }; + isort(is, arraylength(is)); each(i, x, is, printf("%d\n", x); ) |