[Haskell-cafe] Writing a Storable instance for a C union

Nikita Karetnikov nikita at karetnikov.org
Fri Dec 13 16:00:54 UTC 2013


Could anyone explain how to write a Storable instance for MyStruct?
(The key field allows to determine the type of a value inside the
union.)

typedef enum Key_ {
  ONE = 1,
  FOUR = 4,
  TWENTY = 20
} Key;

struct MyStruct {
  Key key;
  union {
    Foo one;
    uint64_t four;
    void *twenty;
  };
};

Also, should I use hsc2hs to make the resulting code portable?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20131213/b87224fb/attachment.sig>


More information about the Haskell-Cafe mailing list