[Haskell-cafe] Re: FFI and returning structs

Maurí­cio briqueabraque at yahoo.com
Wed Nov 19 07:49:28 EST 2008


 >> I have not  found examples of this in  documentation or hackage
 >> packages: how  can I deal with funcions  returning not pointers
 >> to structs but structs thenselves?
 >>
 >> struct example {...
 >>
 >> example function_name (...
 >>
 >> (...)
 >
 > (...)
 >
 > If  it were  my problem,  I would  try a  wrapper  function that
 > returns the same value as an argument - e.g., if you have struct
 > X f(), then
 >
 >   void f_(struct X *x)
 >   {
 >       *x = f();
 >   }
 >
 > (...)   Ironically,  that's  actually  just  what  the  original
 > function is  doing - cf.  "struct return convention",  where the
 > caller  allocates  space  and  passes  a  pointer  as  a  hidden
 > parameter.  (...)

Can I  be sure  things always goes  like that? I  remember reading
somewhere that if, for instance,  a struct is smaller in size than
a pointer (like a struct made of three chars), the struct could be
returned by itself.

Also, why  Haskell FFI  do not  automate that?  As  long as  it is
Storable data, can't it get the pointer and 'peek' it for me?

Thanks,
Maurício



More information about the Haskell-Cafe mailing list