fork download
  1. using System;
  2. using System.Runtime.InteropServices;
  3.  
  4. [StructLayout(LayoutKind.Explicit)]
  5. struct BrokenBeyondRepair
  6. {
  7. [FieldOffset(0)] public int i32_0;
  8. [FieldOffset(0)] public float f32_0;
  9. [FieldOffset(4)] public int i32_1;
  10. [FieldOffset(4)] public float f32_1;
  11. [FieldOffset(0)] public double f64;
  12. [FieldOffset(0)] public long i64;
  13. }
  14.  
  15. public class Test
  16. {
  17. public static void Main()
  18. {
  19. var obj = new BrokenBeyondRepair();
  20. obj.f64 = Math.PI;
  21. Console.WriteLine("i32[0] = {0}", obj.i32_0);
  22. Console.WriteLine("i32[1] = {0}", obj.i32_1);
  23. Console.WriteLine("f32[0] = {0}", obj.f32_0);
  24. Console.WriteLine("f32[1] = {0}", obj.f32_1);
  25. Console.WriteLine("i64[0] = {0}", obj.i64);
  26. Console.WriteLine("f64[0] = {0}", obj.f64);
  27. }
  28. }
Success #stdin #stdout 0.02s 16664KB
stdin
Standard input is empty
stdout
i32[0] = 1413754136
i32[1] = 1074340347
f32[0] = 3.370281E+12
f32[1] = 2.142699
i64[0] = 4614256656552045848
f64[0] = 3.14159265358979