Thank you Marc. Those are all better solutions than my wrapper function.<div><br></div><div>Best regards</div><div><br></div><div>Álvaro</div><div><br></div><div><br><br><div class="gmail_quote">2012/2/6 Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca">feeley@iro.umontreal.ca</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
On 2012-02-06, at 8:08 AM, Marc Feeley wrote:<br>
<br>
> I can reproduce the problem.  It seems to be a bug.  I'll look into it today.<br>
<br>
</div>I can confirm that it is a bug in the C-interface which occurs with opaque types (such as (c-define-type foo "foo")), and "struct" and "union" types when the body of the c-lambda is inline code (the case where the c-lambda body is a function name is handled correctly).<br>


<br>
I'll work on a fix.<br>
<br>
In the meantime, you can use one of the styles given in the attached example.<br>
<br>
Marc<br>
<br>
<br>
(c-declare #<<end-of-c-declare<br>
<br>
#include <stdio.h><br>
<br>
typedef enum { A, B, C } foo;<br>
<br>
void f(foo x) { printf("%d\n", x); }<br>
<br>
end-of-c-declare<br>
)<br>
<br>
;;;---------------------------------------------------------------------------<br>
<br>
;#|<br>
<br>
;; This interface to the "foo" enum type works on C and C++ compilers.<br>
;; The use of ___ASSIGN_NEW_WITH_INIT is needed to avoid a bug in the<br>
;; C-interface that occurs when the body of the c-lambda is not the<br>
;; name of a function (i.e. when the body is inline code).<br>
<br>
(c-define-type foo "foo")<br>
<br>
(define A<br>
  ((c-lambda () foo "___ASSIGN_NEW_WITH_INIT(___result_voidstar,foo,A);")))<br>
<br>
(define B<br>
  ((c-lambda () foo "___ASSIGN_NEW_WITH_INIT(___result_voidstar,foo,B);")))<br>
<br>
(define C<br>
  ((c-lambda () foo "___ASSIGN_NEW_WITH_INIT(___result_voidstar,foo,C);")))<br>
<br>
(define f (c-lambda (foo) void "f"))<br>
;|#<br>
<br>
;;;---------------------------------------------------------------------------<br>
<br>
#|<br>
<br>
;; This interface to the "foo" enum type causes a bug in the<br>
;; C-interface on C and C++ compilers.<br>
<br>
(c-define-type foo "foo")<br>
<br>
(define A ((c-lambda () foo "___result = A;")))<br>
(define B ((c-lambda () foo "___result = B;")))<br>
(define C ((c-lambda () foo "___result = C;")))<br>
<br>
(define f (c-lambda (foo) void "f"))<br>
|#<br>
<br>
;;;---------------------------------------------------------------------------<br>
<br>
#|<br>
<br>
;; This interface works on C and C++ compilers, but is klunky.<br>
<br>
(c-declare #<<end-of-c-declare<br>
<br>
foo get_A() { return A; }<br>
foo get_B() { return B; }<br>
foo get_C() { return C; }<br>
<br>
end-of-c-declare<br>
)<br>
<br>
(c-define-type foo "foo")<br>
<br>
(define A ((c-lambda () foo "get_A")))<br>
(define B ((c-lambda () foo "get_B")))<br>
(define C ((c-lambda () foo "get_C")))<br>
<br>
(define f (c-lambda (foo) void "f"))<br>
|#<br>
<br>
;;;---------------------------------------------------------------------------<br>
<br>
#|<br>
<br>
;; This is an alternate interface to the "foo" enum type.  The<br>
;; explicit cast in the definition of "f" is required when compiling<br>
;; with a C++ compiler because the conversion from int to enum is not<br>
;; implicit in C++.<br>
<br>
(c-define-type foo int) ;; NOTE: using "int" type for "foo"<br>
<br>
(define A ((c-lambda () foo "___result = A;")))<br>
(define B ((c-lambda () foo "___result = B;")))<br>
(define C ((c-lambda () foo "___result = C;")))<br>
<br>
(define f (c-lambda (foo) void "f((foo)___arg1);")) ;; NOTE: explicit cast<br>
|#<br>
<br>
;;;---------------------------------------------------------------------------<br>
<br>
(f A)<br>
(f B)<br>
(f C)<br>
<br>
</blockquote></div><br></div>