I’m reading source code of nginx and find it’s not initializing many of the numerical variables, including ngx_int_t ngx_last_process;,here ngx_int_t defined as long int
#if 0
ngx_last_process = 0;
#endif
So here @Igor Sysoev think it unnecessary to do the initialization?
But in the programe it’s assuming the default value is 0:
for (s = 0; s < ngx_last_process; s++) {
if (ngx_processes[s].pid == -1) {
break;
}
}
Is it guranteed that un-initialized variable will have 0 value in c at all?
External and static variables are initialized to zero by default, this is guaranteed. Automatic and register variables that do not have en explicit initializer will have an indeterminate value (either an unspecified value or a trap representation).
From The Standard:
C89
6.5.7:
C99
6.2.4, §5:
6.7.8, §10:
3.17.2, §1:
indeterminate value: either an unspecified value or a trap representation
3.17.3, §1:
unspecified value: valid value of the relevant type where this International Standard imposes no requirements on which value is chosen in any instance. NOTE An unspecified value cannot be a trap representation.