Skip to content

StructLayoutAttribute.Pack example is wrong #9839

@gewarren

Description

@gewarren

"The example result is wrong, I tested it on .NET 8, the result is:

Size: 32
b1 Offset: 0
b2 Offset: 1
i3 Offset: 4
a4 Offset: 8
d5 Offset: 16

The examples with the decimal field are wrong for .NET 5+. Now there are two 4 byte fields and 1 8byte field (not 4 4byte fields), so the alignment is on 8, and not 4. See this commit."

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.structlayoutattribute.pack?view=net-8.0#code-try-6

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions