-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
type with packed pragma is not properly packed #5824
Comments
I think this is a syntax issue - the "attribute" must come last when using gcc:
|
@markus-oberhumer |
@krux02 You are right - but I recall there was a syntax problem with some older gcc version... Looking at your source once more: I don't think that |
The packed attribute for unions doesn't really make a lot of sense to me. All members of a union have the relative offset of 0, thererefore there is not much it could align. One thing I should note is that the most outer struct does not align the members, but the inner structs to it, but only relative to their size. In other words they add padding bytes so that in case when the inner struct would be allocated aligned in memory the members would be aligned. Just that the inner members are not allocated aligned in memory. Therefore nothing is aligned and the padding bytes are just pure waste. |
Yes, but all this "packed" handling is historically somewhat unstable/buggy ( https://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=attribute%20packed lists 30 open and several hundred closed bugs ), so it probably helps if Nim's codegen does emit as many |
I currently try to implement
offsetof
,alignof
,sizeof
as a compile time feature of my compiler (#5664), and in my tests I found out, that the original nim code generation does not properly pack its types.This is the type I use to test the correctness of my
offsetof
implementation:This test shows the original generated C coder for this exact type:
annotated output:
As you can see, only when the packed attribute is actually propagated to all implicit subtypes it can correctly handle the entire object type.
The text was updated successfully, but these errors were encountered: