fork(2) 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. T t;
  36.  
  37. setValue( (t.s1=&x.s1,&t), 1);
  38. setValue( (t.s2=&x.s2,&t), 2);
  39. setValue( (t.s3=&x.s3,&t), 3);
  40.  
  41. printf( "%d %d %d",x.s1.Value,x.s2.Value,x.s3.Value);
  42.  
  43. return 0;
  44. }
  45.  
  46.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
1 2 3