forked from alex-eg/sex
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:
@@ -788,9 +788,12 @@
|
||||
(c-in-stmt (apply c-begin body)))
|
||||
fl))
|
||||
|
||||
;; MODIFIED FROM UPSTREAM fmt-c: the name and parameters are the
|
||||
;; return type's declarator, so a function returning a function pointer
|
||||
;; is int (*get (void))(int), not int (*)(int) get (void)
|
||||
(define (c-prototype type name params . o)
|
||||
(c-wrap-stmt
|
||||
(cat (c-type type) " " (c-expr name) " (" (c-param-list params) ")"
|
||||
(cat (c-type type (cat (c-expr name) " (" (c-param-list params) ")"))
|
||||
(fmt-join/prefix c-expr o " "))))
|
||||
|
||||
(define (c-static x) (cat "static " (c-expr x)))
|
||||
@@ -808,10 +811,14 @@
|
||||
(cond
|
||||
((pair? type)
|
||||
(case (car type)
|
||||
;; MODIFIED FROM UPSTREAM fmt-c: the declarator goes round the
|
||||
;; name, inside the return type's own, so a function type
|
||||
;; returning one nests: void (*(*g)(int))()
|
||||
((%fun)
|
||||
(cat (c-type (cadr type) #f)
|
||||
" (*" (or name "") ")("
|
||||
(fmt-join (lambda (x) (c-type x #f)) (caddr type) ", ") ")"))
|
||||
(c-type (cadr type)
|
||||
(cat "(*" (or name "") ")("
|
||||
(fmt-join (lambda (x) (c-type x #f)) (caddr type) ", ")
|
||||
")")))
|
||||
;; MODIFIED FROM UPSTREAM fmt-c: a nameless declarator -- an
|
||||
;; array parameter of a function type, where C has no room
|
||||
;; for a name -- arrives as #f, and upstream printed it
|
||||
@@ -847,10 +854,14 @@
|
||||
(cond
|
||||
((pair? type)
|
||||
(case (car type)
|
||||
;; MODIFIED FROM UPSTREAM fmt-c: the declarator goes round the
|
||||
;; name, inside the return type's own, so a function type
|
||||
;; returning one nests: void (*(*g)(int))()
|
||||
((%fun)
|
||||
(cat (c-type (cadr type) #f)
|
||||
" (*" (or name "") ")("
|
||||
(fmt-join (lambda (x) (c-type x #f)) (caddr type) ", ") ")"))
|
||||
(c-type (cadr type)
|
||||
(cat "(*" (or name "") ")("
|
||||
(fmt-join (lambda (x) (c-type x #f)) (caddr type) ", ")
|
||||
")")))
|
||||
;; MODIFIED FROM UPSTREAM fmt-c: a nameless declarator -- an
|
||||
;; array parameter of a function type, where C has no room
|
||||
;; for a name -- arrives as #f, and upstream printed it
|
||||
|
||||
Reference in New Issue
Block a user