kit

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

6_5_15_ternary_null_func_ptr_slot.c (789B)


      1 typedef int (*Callback)(int);
      2 
      3 struct WalkerLike {
      4   void* parse;
      5   Callback expr;
      6   Callback select;
      7   Callback select2;
      8   int depth;
      9   unsigned short code;
     10   unsigned short flags;
     11   void* ctx;
     12 };
     13 
     14 static int callback(int x) { return x + 7; }
     15 
     16 static int run_case(int no_select) {
     17   struct WalkerLike w;
     18   w.parse = (void*)0x12345678UL;
     19   w.expr = callback;
     20   w.select = no_select ? 0 : callback;
     21   w.select2 = 0;
     22   w.depth = 3;
     23   w.code = 4;
     24   w.flags = 5;
     25   w.ctx = &w;
     26   if (w.parse != (void*)0x12345678UL) return 1;
     27   if (no_select) {
     28     if (w.select != 0) return 2;
     29   } else {
     30     if (w.select != callback) return 3;
     31     if (w.select(35) != 42) return 4;
     32   }
     33   return 42;
     34 }
     35 
     36 int test_main(void) {
     37   if (run_case(0) != 42) return 1;
     38   if (run_case(1) != 42) return 2;
     39   return 42;
     40 }