write #() as {0}

{} is C23's. #() is all zeros, which C11 spells {0}, whatever it
initializes.
This commit is contained in:
2026-10-17 17:35:48 +03:00
parent 83a1355b6f
commit 26f5df1898
3 changed files with 23 additions and 6 deletions

View File

@@ -1095,6 +1095,19 @@
(emits? (string-append "(struct h ((n int) (p (* int))))"
"(var g (struct h) #((struct h) : 3 #([int 2] : 1 2)))")
"{3, (int [2]){1, 2}}"))
;; #() is all zeros; {} says so only from C23, and {0} in C11
(test-assert "empty braces are zeros"
(emits? "(struct pt ((x int))) (var g (struct pt) #())" "struct pt g = {0};"))
(test-assert "in a function and in a compound literal as well"
(emits? (string-append "(struct pt ((x int)))"
"(fn f () void (var p (struct pt) #((struct pt) :)))")
"(struct pt){0}"))
(test-assert "inside other braces"
(emits? (string-append "(struct pt ((x int))) (struct h ((a (struct pt)) (n int)))"
"(var g (struct h) #(#() 1))")
"{{0}, 1}"))
(test-assert "and for a scalar"
(emits? (in-fn "(var n int #())") "int n = {0};"))
(test-assert "while a value is still its braces"
(emits? (string-append "(struct pt ((x int))) (struct h2 ((a (struct pt))))"
"(var g (struct h2) #(#((struct pt) : 1)))")