boot2

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

057-block-static.c (542B)


      1 // tests/cc-parse/57-block-static.c — block-scope static survives across
      2 // calls and does not collide across functions. §I.
      3 //
      4 // Two distinct `static int n` instances must mangle to distinct labels.
      5 int incr(void) {
      6     static int n = 0;
      7     n = n + 1;
      8     return n;
      9 }
     10 int decr(void) {
     11     static int n = 100;
     12     n = n - 1;
     13     return n;
     14 }
     15 int main(void) {
     16     incr();
     17     decr();
     18     decr();
     19     // incr() returns 1; second decr returned 98.
     20     // Result = incr() * 10 + decr() = 2 * 10 + 97 = 117.
     21     return incr() * 10 + decr();
     22 }