typedef enum strangeness pasted by retroj on Fri Apr 27 04:21:26 2012

;; given this C code:

typedef enum {
    val1,
    val2,
    val3
} some_enum;


;; this compiles:

(define-foreign-type some-enum "some_enum")

;; this does not compile:

(define-foreign-enum-type (some-enum "some_enum")
 (some-enum->int int->some-enum)
 val1 val2 val3)

no title pasted by zbigniew the exhausted on Fri Apr 27 05:40:07 2012

; when you try to actually use the first one it will not compile either

(define-foreign-type some-enum "some_enum")
(define-foreign-variable val1 "some_enum" "val1")
val1

; that is what the latter expands to, more or less

no title added by retroj on Fri Apr 27 05:44:55 2012


(import chicken scheme foreign foreigners)

#>
typedef enum {
    pain,
    suffering,
    fear
} garmonbozia;

void creepy_dream (garmonbozia *x) {
    printf("give me back my garmonbozia!\n");
    *x = fear;
}
<#

;;; this compiles:
(define-foreign-type garmonbozia "garmonbozia")

;;; this does not:
;; (define-foreign-enum-type (garmonbozia "garmonbozia")
;;   (garmonbozia->int int->garmonbozia)
;;   pain suffering fear)

(define (creepy-dream)
  (let-location ((a int))
    ((foreign-lambda void creepy_dream (c-pointer garmonbozia))
     (location a))
    a))

(print (creepy-dream))