fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct MainStruct {
  5.  
  6. struct SubStruct1 {
  7. int Value;
  8. } s1;
  9.  
  10. struct SubStruct2 {
  11. int Value;
  12. } s2;
  13.  
  14. struct SubStruct3 {
  15. int Value;
  16. } s3;
  17.  
  18. } MainStruct_t;
  19.  
  20. typedef union {
  21. struct SubStruct1 *s1;
  22. struct SubStruct2 *s2;
  23. struct SubStruct3 *s3;
  24. int Value;
  25. } T;
  26.  
  27. void setValue( T **t, int i )
  28. {
  29. (*t)->Value=i;
  30. }
  31.  
  32. int main()
  33. {
  34. MainStruct_t x;
  35. printf("%d %d %d\n",x.s1.Value,x.s2.Value,x.s3.Value);
  36.  
  37. {
  38. T t1={&x.s1},t2={.s2=&x.s2},t3={.s3=&x.s3};
  39.  
  40. setValue( &t1, 1);
  41. setValue( &t2, 2);
  42. setValue( &t3, 3);
  43. }
  44.  
  45. printf("%d %d %d\n",x.s1.Value,x.s2.Value,x.s3.Value);
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
-1081055708 -1081055700 -1217364403
1 2 3