kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

6_7_2_1_06_mutual_struct_ptr.c (514B)


      1 /* Mutually recursive structs through pointers: A holds B*, B holds A*.
      2  * Walking either type for CG-id construction needs cycle-breaking that
      3  * tracks every record currently being walked (not just the immediate
      4  * one), otherwise the walk infinite-recurses A→B*→A→B*... and stack-
      5  * overflows. */
      6 struct A;
      7 struct B;
      8 struct A {
      9   int x;
     10   struct B* b;
     11 };
     12 struct B {
     13   int y;
     14   struct A* a;
     15 };
     16 int test_main(void) {
     17   struct B b = {30, 0};
     18   struct A a = {12, &b};
     19   b.a = &a;
     20   return b.a->x + a.b->y;
     21 }