Skip to content

[dart:ffi] Structure padding and packing in C #43247

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

Closed
mannprerak2 opened this issue Aug 29, 2020 · 1 comment
Closed

[dart:ffi] Structure padding and packing in C #43247

mannprerak2 opened this issue Aug 29, 2020 · 1 comment

Comments

@mannprerak2
Copy link

mannprerak2 commented Aug 29, 2020

For a struct marked with __attribute__((packed)) -

typedef struct __attribute__((packed))
{
    char a;
    int b;
} A;

The layout is as follows (Generated using clang -Xclang -fdump-record-layouts test.c)-

*** Dumping AST Record Layout
         0 | A
         0 |   char a
         1 |   int b
           | [sizeof=5, align=1]

Layout without __attribute__((packed))

*** Dumping AST Record Layout
         0 | A
         0 |   char a
         4 |   int b
           | [sizeof=8, align=4]

Dart will automatically add relevant padding(so that the int b starts at the 4-byte boundary) If I declare a class A extends ffi.Struct.

There should someway to specify to dart VM how to pack a Struct.

@mannprerak2 mannprerak2 changed the title Structure padding and packing in C [dart:ffi] Structure padding and packing in C Aug 29, 2020
@mannprerak2
Copy link
Author

Duplicate of #38158

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

1 participant