<div dir="ltr"><div class="gmail_quote"><div dir="ltr">Storable instances have a size, given by sizeOf.<div><br></div><div>In many cases, we're not interested in peeking/poking data but only passing it opaquely via the FFI. A common use case is when the C API offers an "init" function such as:</div><div><br></div><div>    void mycontext_init(mycontext *context);</div><div><br></div><div>For these cases it would be useful to know the size of "mycontext", so we could malloc it and pass a pointer to mycontext_init. </div><div><br></div><div>Also, it allows Haskell-side code to decide how it wants to allocate the data, perhaps using some other (external) mechanism not related to the specific API that the FFI bindings are wrapping.</div><div><br></div><div>c2hs would benefit by allowing users to use the '+' notation in function parameters (which generate  malloc-and-pass style code), without having to guess the size of the structure. Instead, it could simply use the Sizable (TM) instance to get the size, and the user will define Sizable in any way they want (for example, using the {#sizeof#} macro, which is somewhat unreliable, or by hard-coding or manually entering the size or by some other method).</div><div><br></div><div><br></div><div>Your thoughts are much appreciated!</div><div><br></div><div><br></div></div>
</div><br></div>