boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

058-fnptr-tab.c (523B)


      1 // tests/cc-parse/58-fnptr-tab.c — array of fn pointers initialised
      2 // with named functions. §L.3.
      3 //
      4 // `int (*tab[])()` is currently outside parse-fn-params (Agent 2),
      5 // so we use an explicit typedef. Member access via tab[i] is also
      6 // pending; read elements via pointer arithmetic over &tab as
      7 // fnptr*.
      8 typedef int (*fnptr_t)(void);
      9 int f1(void) { return 1; }
     10 int f2(void) { return 2; }
     11 fnptr_t tab[] = { f1, f2 };
     12 int main(void) {
     13     fnptr_t *p = (fnptr_t *)&tab;
     14     return (*(p + 0))() + (*(p + 1))() * 10;
     15 }