111,125
社区成员
发帖
与我相关
我的任务
分享
union testunion
{
double a[3];
double b;
};
testunion aaaa;
aaaa.a[0]=100;
aaaa.a[1]=2;
cout<<sizeof(aaaa)<<" "<<aaaa.b<<endl;
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Auto)]
struct testunion
{
[FieldOffset(0),MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public double[] a;
[FieldOffset(8)]
public double b;
}
testunion aaaa=new testunion();
aaaa.a=new double[]{1,2,3};
Console.WriteLine(Marshal.SizeOf(aaaa)+"\t"+aaaa.b);
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Auto)]
struct testunion
{
[FieldOffset(0),MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public double[] a;
[FieldOffset(8)]
public double b;
}
union testunion
{
double a[3];
double c;
double b[2];
};
testunion aaaa;
aaaa.a[0]=100;
aaaa.a[1]=2;
cout<<sizeof(aaaa)<<" "<<aaaa.b[1]<<endl;
[FieldOffset(0)]
float f1;
[FieldOffset(0)]
float f2;
[FieldOffset(0)]
double d;
[FieldOffset(0),MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public double[] a;
union testunion
{
double a[3];
double c;
double b;
};
testunion aaaa;
aaaa.a[0]=100;
aaaa.a[1]=2;
cout<<sizeof(aaaa)<<" "<<aaaa.b<<endl;