[Mono-dev] Marshalling: Bug in StructLayout?

Paolo Molaro lupus at ximian.com
Mon Aug 20 04:13:56 EDT 2007


On 08/18/07 Rolf Bjarne Kvinge wrote:
> Structs may be padded according to the platform you're running on, so it's not a bug.
> 
> MSDN says about SequentialLayout: The members of the object are laid
> out sequentially, in the order in which they appear when exported to
> unmanaged memory. The members are laid out according to the packing
> specified in StructLayoutAttribute.Pack, and can be noncontiguous.
> 
> You have to use explicit layout (or StructLayoutAttribute.Pack) to
> get the correct structure on all platforms.

In general, people should never ever use explicit layout or
StructLayoutAttribute.Pack if they are writing portable code: it is
almost guaranteed that people get the combination wrong, because they
don't understand what the semantics of the option is (especially pack).

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better



More information about the Mono-devel-list mailing list