boot2

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

130-static-decl-def.c (1016B)


      1 /* C 6.2.2 ¶4 — linkage inherits from the prior declaration. tcc.c
      2  * relies on this in places like:
      3  *   static void gfunc_call(int);    // forward, internal linkage
      4  *   ...
      5  *   void gfunc_call(int n) { ... }  // omits `static` but inherits it
      6  *
      7  * Both the decl and the def must point at the same internal-linkage
      8  * label; the merge in scope-bind!/sym-merge has to carry the static
      9  * forward so cc.scm doesn't split them across two label namespaces.
     10  */
     11 
     12 /* Pattern A — static decl, plain def. */
     13 static int helper_a(int);
     14 int helper_a(int x) { return x + 100; }
     15 
     16 /* Pattern B — static decl, static def (explicit on both sides). */
     17 static int helper_b(int);
     18 static int helper_b(int x) { return x + 200; }
     19 
     20 /* Pattern C — plain decl, plain def. External linkage end-to-end. */
     21 int helper_c(int);
     22 int helper_c(int x) { return x + 300; }
     23 
     24 int main(int argc, char **argv) {
     25     if (helper_a(1) != 101) return 1;
     26     if (helper_b(2) != 202) return 2;
     27     if (helper_c(3) != 303) return 3;
     28     return 0;
     29 }