Bug 6148 - sizeof() does't apply default padding and doesn't repsect Pack=N for explicit layout structs
Summary: sizeof() does't apply default padding and doesn't repsect Pack=N for explicit...
Alias: None
Product: Runtime
Classification: Mono
Component: Interop ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-07-16 16:24 UTC by Dan Shechter
Modified: 2012-07-18 11:04 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Sample file (685 bytes, text/x-csharp)
2012-07-16 16:24 UTC, Dan Shechter

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Dan Shechter 2012-07-16 16:24:24 UTC
Created attachment 2209 [details]
Sample file

When a struct is defined with explicit layout, it should be applied with the default padding just like any other struct.
In addition, Pack=N values passed in the StructLayout attribute should be respected, but they are ignored in mono.

The supplied sample file can be compiled like this:
dmcs -unsafe+ b.cs -out:b.exe -target:exe

On mono, this returns:
dans@cartman:~$ ./b.exe 
XxX 17 17

On Windows/MS.NET:
$ ./b.exe 
XxX 20 18

I will attempt to create a fix / pull-request for this
Comment 1 Rodrigo Kumpera 2012-07-18 11:04:37 UTC
Pulled your fix. Thanks!