fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <algorithm>
  4. #include <random>
  5. #include <x86intrin.h>
  6.  
  7. #pragma pack(push, 1)
  8. struct test{
  9. union{
  10. struct{char data[8]; };
  11. struct{char a; float x; char b[3]; };
  12. };
  13. };
  14. #pragma pack(pop)
  15.  
  16. union soft{
  17. float x;
  18. char c[4];
  19. };
  20.  
  21. int main()
  22. {
  23. soft a;
  24. a.x=124.12414;
  25. test b;
  26. for (int i=0;i<4;i++){
  27. b.data[i+1]=a.c[i];
  28. }
  29. float* m=&b.x;
  30. printf("%.6f\n",a.x);
  31. printf("%.6f\n",*(float*)&b.x);
  32. printf("%.6f\n",*(float*)(&b.data[1]));
  33. printf("%.6f\n",*m);
  34.  
  35. }
  36.  
Success #stdin #stdout 0s 4504KB
stdin
Standard input is empty
stdout
124.124138
124.124138
124.124138
124.124138