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 87676b24fb
commit 36b37f34c1
3 changed files with 23 additions and 6 deletions

View File

@@ -368,13 +368,16 @@ forms, and what remains."
;;; language. `:' is the separator because it is the one thing that can
;;; be neither a type word nor an expression -- a named form would be a
;;; C identifier, and so shadowable (see issue #36).
;;;
;;; #() is all zeros, and C11 spells that {0}: {} came in only with C23
(define (walk-initializer elements)
(let ((parts (list-split (remove comment-form? elements) ':)))
(let ((parts (list-split (remove comment-form? elements) ':))
(filled (lambda (es) (if (null? es) (list 0) (walk-designators es)))))
(if (null? (cdr parts))
(list->vector (walk-designators (car parts)))
(list->vector (filled (car parts)))
(cons* '%compound
(walk-type (maybe-unwrap-type (car parts)))
(walk-designators (cadr parts))))))
(filled (cadr parts))))))
;;; `.field value' is a designated initializer; anything else is
;;; positional. C lets the two be mixed, and nothing here stops it. A