[gambit-list] c-interface: relaxing type checking on the scheme side

James Long longster at gmail.com
Tue Feb 5 01:09:49 EST 2008


Is there anyway to specify multiple tags for a type so that, for
example, I could pass either a float or an int to a c function?  C's
basic type coercion, in my opinion, is not a bad thing and it helps
code become less cluttered.

Well, lets take a step back.  I just realized I can't even
successfully map any primitive type to a new type.  For example:

(c-declare #<<END

int add(int a) {
    return a+5;
}

END
)

(c-define-type num (type "int" #f))

(define add
  (c-lambda (num) int "add"))

Compiling and calling `(add 5)` throws a type error for the argument
(can't convert to C type).  I thought the third parameter of the
'type' expression bypassed type checking.  What am I doing wrong?

Assuming I get that working, I could just bypass type checking
altogether, but I don't want that.  I was hoping to define a type
along the lines of

(c-define-type real (type "float" "float int"))

where the third parameter of 'type' is a space-delimited list of type
tags that should pass for this type.  Is this possible, or on the todo
list for c-interface improvements?

Thanks!


-- 
James Long



More information about the Gambit-list mailing list