Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for flexible array members #353

Open
yallop opened this issue Feb 17, 2016 · 4 comments
Open

Support for flexible array members #353

yallop opened this issue Feb 17, 2016 · 4 comments

Comments

@yallop
Copy link
Owner

yallop commented Feb 17, 2016

A common pattern in C libraries is to make the final member of a struct an array whose length is determined at runtime, like this example from the sanlock library:

struct sanlk_resource {
    char lockspace_name[SANLK_NAME_LEN]; /* terminating \0 not required */
    char name[SANLK_NAME_LEN]; /* terminating \0 not required */

       /* ... */

    uint32_t num_disks;
    /* followed by num_disks sanlk_disk structs */
    struct sanlk_disk disks[0];
};

Ctypes doesn't currently offer much/any support for this pattern, but it's sufficiently common that we ought to support it.

@yallop
Copy link
Owner Author

yallop commented Feb 17, 2016

/cc @simonjbeaumont

@simonjbeaumont
Copy link

@yallop thanks for confirming the workaround too :)

@simonjbeaumont
Copy link

I took the time to blog about the current workaround when these are required. http://simonjbeaumont.com/posts/ocaml-ctypes-flexible-array-member/

@yallop
Copy link
Owner Author

yallop commented Mar 31, 2016

Thanks! These blog posts are extremely useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants