Skip to content

translate-c: Implement flexible arrays #8891

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

Merged
merged 1 commit into from
Jun 11, 2021

Conversation

ehaas
Copy link
Contributor

@ehaas ehaas commented May 24, 2021

Fixes #8759

@iguessthislldo
Copy link

Thanks! This was blocking me, so I was just about to ask in the issue if I could take a crack at it if no one else was planning to. I will try this out later today.

@Vexu Vexu added the translate-c C to Zig source translation feature (@cImport) label May 31, 2021
@ehaas ehaas force-pushed the translate-c-flexible-arrays branch from fd03c02 to 4a7df9c Compare June 10, 2021 17:32

const field_index = field_decl.getFieldIndex();
const bit_offset = layout.getFieldOffset(field_index); // this is a target-specific constant based on the struct layout
const byte_offset = bit_offset / 8;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This division assumes 8 bits per byte; is it worth using toCharUnitsFromBits to ensure it works on exotic platforms with different-sized bytes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highly doubt this will ever become an issue.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, zig still hasn't decided to support non-octet bytes
#7693

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Imported C Structs with VLAs
4 participants