write #() as {0}
{} is C23's. #() is all zeros, which C11 spells {0}, whatever it
initializes.
This commit is contained in:
@@ -1160,6 +1160,19 @@ whitespace aside, THEN?"
|
||||
(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)))")
|
||||
|
||||
Reference in New Issue
Block a user