-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InlineArray reports wrong size when struct size is specified #110962
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
The design doc covers this: https://github.com/dotnet/runtime/blob/main/docs/design/features/InlineArrayAttribute.md
Notably this does lead to some unexpected scenarios such as the following not holding:
Likewise the This is potentially a case that should've just been blocked, much as |
Yes, Size=X should be blocked. It was probably missed because you’d typically assume that explicit size is not used with sequential layout. |
If it is decided to not block StructLayout.Size, the official API documentation for
If StructLayout.Size is going to be blocked, the API documentation can be left as it currently is. |
If it's an unexpected, and frankly illogical, to do what @hez2010 did, I'd personally argue that is should be blocked. If one wants to do something like this (an inline array of padded structs), they can define two types: one with an explicit size and one with the // or a union of `int` and `char[42]`
struct Padded
{
int value;
char[38] __padding;
};
struct Actual
{
Padded[2] elements;
}; [StructLayout(LayoutKind.Sequential, Size = 42)]
public struct Padded
{
public int Value;
}
[InlineArray(2)]
public struct Actual
{
private Padded _element0;
} |
Description
InlineArray reports wrong size when struct size is specified.
Reproduction Steps
Expected behavior
42
This should be equivalent to
Actual behavior
84
Regression?
No
Known Workarounds
No
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: