[racket] FFI question again - how to get a string back from C

From: keydana at gmx.de (keydana at gmx.de)
Date: Sun Jun 12 02:41:14 EDT 2011

Hi Thomas,

thank you, too, very much for your solution! I had already successfully tried Ryan's way, but it's always good and instructive to learn several ways - now I know 2 ways to allocate a byte buffer and to cast it to a string afterwards :-)

I've tried your solution, and it worked perfectly, too (after exchanging 'atomic and the length argument to malloc, which seem to have to appear in opposite order).
In fact to be honest, I do not really understand the reason why I have to allocate a byte buffer here - what difference does it make to a char **, shouldn't both just be consecutive places in memory filled with ascii characters (sorry for asking the c-agnostic stuff again, but this project might be a chance to finally learn about these things, too :-;)

BTW thanks for pointing out the (and result output)  wrapper return type - I like this, it's more concise than the (values result output) return I was using before, I don't really do anything with the "result" boolean anyway...

One last BTW,

> This wrapper function takes the date object and a format string as
> arguments, allocates a buffer for the formatted result that is 128
> bytes larger than the format string 

I had also hoped to do something like this, but then I realized that you can't conclude from the length of the format string on the length of the output, as the format strings might not be of the straightforward "yyyy-mm-dd" - like types, which I normally only tend to use :-;


Posted on the users mailing list.