At Thu, 31 Mar 2016 15:00:35 -0700 (PDT), Pedro Caldeira wrote:
> Hello everyone,
> 
> I am trying to use a set of bindings to SDL2 and I am at loss on how to use C 
> unions.
> 
> If I understood correctly both make-union-type and _union procedures create a 
> new ctype; but how do you actually create instances of these unions?

One way is to use `malloc` to allocate space and `ptr-ref` to treat the
memory as a union:

 #lang racket
 (require ffi/unsafe)

 (define _iord (_union _int64 _double))

 (define u (ptr-ref (malloc _iord) _iord))
 (union-set! u 1 4.2)
 (union-ref u 0)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to