[squeak-dev] FFI structs

Bert Freudenberg bert at freudenbergs.de
Wed Oct 29 15:48:19 UTC 2014


On 29.10.2014, at 06:59, Annick Fron <list at afceurope.com> wrote:

> I I have a C struct with a char*
> 
> struct result {
> 	char* time }
> 
> I define an ExternalStructure in FFI , with one field of type char* (note that the syntax char [5] is not accepted ! ).
> 
> defineFields generates the accessors time and time:
> 
> If I use 
> time: ’05:45’
> 
> I get an error.
> How do I set a string value in an ExternalStructure ?
> 
> Annick

Just like in C. You need to create a pointer to a char array and store that. Which means you need to allocate some bytes (ExternalAddress allocate: byteSize + 1), copy your string there (byteAt:put:), add a terminating 0 byte, then store the address of that in your struct. Be sure to free the memory allocated when you're done.

I think there used to be a helper function for that but I can't find it (only found fromCString). 

- Bert -

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4142 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20141029/5ba038c5/smime.bin


More information about the Squeak-dev mailing list