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