Does C # have the equivalent of #pragma package in C ++?

C # provides StructLayoutAttribute.Pack, but its behavior "every member gets at least the specified alignment, whether he wants it or not," whereas the behavior of the #pragma package in C ++ "every member gets the alignment he wants, if only he wants more than the specified alignment, and in this case he does not guarantee more than that. "

Is there a way to force the layout of a structure in C # to be the same as the layout of a similar structure in C ++ with a specific package #pragma, besides using StructLayout (LayoutKind.Explicit) and FieldOffset for each member, or inserting unused fill elements?

+5
source share
1 answer

After experimenting with StructLayout.Pack, it seems like it really does the same thing as #pragma pack in C ++. Assuming that the MSDN documentation for StructLayout.Pack (which required the behavior described in my original post) was an error.

+6
source

All Articles