keep an array literal a global pointer is set to
At file scope every compound literal was cut down to its braces, right for a value and not for an array a pointer points at: the address of a static object is a constant, and its braces alone the pointer's own.
This commit is contained in:
@@ -1061,7 +1061,24 @@
|
||||
(test-assert "ahead of it"
|
||||
(let ((c (sex->c "(var f (fn ((x int)) int) (lambda ((x int)) int (return x)))")))
|
||||
(< (string-contains c "static int λ0_f (int x)")
|
||||
(string-contains c "(*f)(int) = λ0_f")))))
|
||||
(string-contains c "(*f)(int) = λ0_f"))))
|
||||
;; every compound literal lost its type at file scope, which is right
|
||||
;; for a value and not for an array a pointer is set to: that is the
|
||||
;; address of a static object, and its braces alone the pointer's own
|
||||
(test-assert "an array a pointer is set to keeps its type"
|
||||
(emits? "(var gp (* int) #([int 3] : 1 2 3))" "int * gp = (int [3]){1, 2, 3}"))
|
||||
(test-assert "in a field named for it"
|
||||
(emits? (string-append "(struct h ((p (* int)) (n int)))"
|
||||
"(var g (struct h) #(.p #([int 2] : 1 2) .n 3))")
|
||||
"{.p = (int [2]){1, 2}, .n = 3}"))
|
||||
(test-assert "or one in its place"
|
||||
(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}}"))
|
||||
(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)))")
|
||||
"h2 g = {{1}}")))
|
||||
|
||||
;; fmt-c kept the first star after a tag and dropped what followed it,
|
||||
;; and took an enum's star for its list of values
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(compilation "-- -std=c11 -pedantic-errors")
|
||||
(input)
|
||||
(output "c11: 42 43 6 4 6 12"
|
||||
(output "c11: 42 43 6 4 6 12 5"
|
||||
"trigraphs: what??! ??= ???( ??/")
|
||||
(return 0)
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
(sum shape ((square ((side int))) (dot ())))
|
||||
|
||||
(var corner _ #(point : 2 3))
|
||||
(var primes (* int) #([int 3] : 2 3 5))
|
||||
(var unit _ (shape/square 1))
|
||||
(var pair [_ 2] #(#(point : 1 2) #(point : 3 4)))
|
||||
|
||||
@@ -44,8 +45,8 @@
|
||||
(var k int 1)
|
||||
(var add-k (closure ((int)) int)
|
||||
(closure ((v int)) int (k) (return (+ v k))))
|
||||
(printf "c11: %d %d %d %d %d %d\n"
|
||||
(printf "c11: %d %d %d %d %d %d %d\n"
|
||||
(.area p) (add-k (.area p)) (+ (sides (shape/square 1)) (sides (shape/dot)) 2)
|
||||
(sides unit) (.area corner) (.area [pair 1]))
|
||||
(sides unit) (.area corner) (.area [pair 1]) [primes 2])
|
||||
(printf "trigraphs: %s\n" "what??! ??= ???( ??/")
|
||||
(return 0))
|
||||
|
||||
Reference in New Issue
Block a user