Skip to content

Figure out what to do with flexible array members #4758

@tgross35

Description

@tgross35

A number of C structures make use of a flexible array member:

struct sockaddr {
     sa_family_t     sa_family;      /* Address family */
     char            sa_data[];      /* Socket address */
 };

When mapped to Rust, most of these are a public field of type [T; 0]. We could instead map them to Rust unsized [c_char] fields.

The current pattern has a few advantages over using DSTs:

  • size_of works to get you the base size
  • You can offset_of the field to get the start of the array if you need it
  • You can work with the type through references, they don't need to be constructed as fat pointers
  • Rust's flexible array members aren't all that convenient to work with

I expect we'll probably want to stick with the current pattern, but it's worth double checking that there isn't something better for 1.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent issues with `libc`.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions