I'm running in to the exact same problem as explained here. Unfortunately, I don't understand what exactly was changed to fix the situation. Did the OP hint to Swift the size of flexible array member to make it visible in Swift? Did the OP modify the C library? I'd like to avoid doing that.
I'm using a C library in Swift that returns a struct with a flexible array member "mbody" at the end.
typedef struct {
size_t size;
char mbody[];
} msg
In Swift, when this struct is returned, I have access to the property "size", but not the property "mbody". I've confirmed the mbody is being set properly. A simplified version of the code that initializes the C struct is here:
const size_t mem_size = msgcount * MSGBOX_SIZE;
msg* ret = malloc(sizeof(msg) + mem_size);
if (!ret)
return NULL;
ret->size = mem_size;
memcpy(ret->mbody, msgrecord, MSGBOX_SIZE);
Why is Swift not picking up the size of msg->mbody? Is it a compiler setting? I set it to C99.