019-static.c (487B)
1 /* tests/cc-e2e/19-static.c — block-scope `static int n` retains state across calls. 2 * Split from 01-kitchen-sink. */ 3 4 int counter(void) { 5 static int n = 0; 6 n = n + 1; 7 return n; 8 } 9 10 int test_static(void) { 11 int a = counter(); /* 1 */ 12 int b = counter(); /* 2 */ 13 int c = counter(); /* 3 */ 14 return a + b + c; /* 6 */ 15 } 16 17 int main(int argc, char **argv) { 18 if (test_static() != 6) return 1; 19 return 0; 20 }