fork(3) download
  1. #include <stdio.h>
  2. struct Base {
  3. int num;
  4. #define DEFAULT_BASE() {.num =1}
  5. };
  6.  
  7. struct DerivedA{
  8. struct Base base;
  9. int a;
  10. #define DEFAULT_DERIVEDA() {DEFAULT_BASE() , .a = 2}
  11. };
  12.  
  13. struct DerivedB{
  14. struct Base base;
  15. int b;
  16. #define DEFAULT_DERIVEDB() {DEFAULT_BASE() , .b = 2}
  17. };
  18.  
  19. struct DerivedA instA = DEFAULT_DERIVEDA();
  20. struct DerivedB instB = { DEFAULT_BASE() , .b = 3 };
  21.  
  22. void func(struct Base * p){
  23. p->num++;
  24. }
  25.  
  26. int main() {
  27. func(&instA);
  28. func(&instB);
  29. printf("A->num:%d , a:%d\nB->num:%d , b:%d" , instA.base.num , instA.a , instB.base.num , instB.b );
  30. }
Success #stdin #stdout 0s 4336KB
stdin
Standard input is empty
stdout
A->num:2 , a:2
B->num:2 , b:3