Open AffluentOwl opened 5 months ago
Tagging subscribers to this area: @dotnet/area-system-runtime
Notably none of the examples given on the docs page are redundant. They are very explicitly showing the differences between under packing, overpacking, and matching the natural packing and contrasting it with how they impact fields whose natural packing are less than, equal to, or the same as the packing of the struct.
The example you gave explicitly shows another struct, but is in the same vein as the other examples the page already gives and is trying to showcase, which is that the actual packing
of a struct is the lesser of the specified packing
and natural packing
of the struct. The natural packing
of the struct is then the maximum of the actual packing
of all fields of the struct.
This is why I always preferred PHP's documentation over MSDN. Their functionality to allow users to comment on the official documentation gives users an easy way to share additional knowledge and examples with each other. Combine this with the fact that github is often a walled garden to search engines, and we can only pray that this knowledge is distributed in the next release of ChatGPT.
Consider the following non-obvious behavior where an inner struct's packing can affect where it is laid out in a parent struct. The documentation gives 7 nearly redundant examples, but does not give an example of nested packing.