Does he do the same after preprocessing?
No, both do not necessarily behave the same.
This initialization is guaranteed to work only once :
static int i = 42;
This appointment
static int i = 0; if (!i) i = 42;
no, because each time the program stream reaches line X and i is 0 , then i set to 42 (again).
Examples:
#include <stdio.h> void foo(int inew) { static int i = 42; printf("%d\n", i); i = inew; } void bar(int inew) { static int i = 0; if (!i) i = 42; printf("%d\n", i); i = inew; } int main(void) { foo(43); foo(0); foo(44); printf("\n"); bar(43); bar(0); bar(44); return 0; }
Run it and see the difference:
42 43 0 42 43 42
source share