nest a function type's declarator round the name

A function type's return was written ahead of its declarator, so one
returning a function pointer came out int (*)(int) get (void), and a
variable of such a type as void (*)() (*g)(int).
This commit is contained in:
2026-10-18 22:02:55 +03:00
parent 4e71d327f5
commit 18962f43ad
3 changed files with 40 additions and 8 deletions

View File

@@ -9,7 +9,8 @@
"unnamed parameters: 7 -1 2"
"typedefs: hi 4 2"
"sizeof a pointer type: 1 1"
"dimensions: 6 12 5")
"dimensions: 6 12 5"
"returned function: 42")
(return 0)
;;; Three questions about a written type that used to be answered in
@@ -29,6 +30,9 @@
(typedef vec4 [float 4])
(typedef unary (fn ((small)) small))
(fn successor ((n int)) int (return (+ n 1)))
(fn stepper () (fn ((int)) int) (return successor))
(define CAP 2)
;;; a parameter that names nothing is a type, however many words it
@@ -101,4 +105,7 @@
(var g [int 2 3] #(#(0 1 2) #(3 4 5)))
(printf "dimensions: %zu %zu %d\n"
(/ (sizeof g) (sizeof int)) (sizeof [g 0]) [g 1 2])
;; a function type is a declarator wrapped round the name
(printf "returned function: %d\n" ((stepper) 41))
(return 0))