Why the following behavior is allowed by most implementations of C ? If we a use a variable itself to define it, like this:
#include <stdio.h>
int main()
{
int a = 9;
int b = ( a +b );
printf("%d",b);
}
I know that the garbage value of b
will be used but there should be some compile time warnings . It sounds a little weird to me. In languages like Python it is illegal to do such stuff :
>>> b = 9
>>> a = a + b
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
a = a + b
NameError: name 'a' is not defined
I guess Python does not put a variable to the current namespace until it is well-defined (i.e. it has a value within the current scope) while in C the above statement breaks like this:
int b = 9;
int a; // put to namespace or whatever a lookup table with garbage value
a = a + b;
It would be nice if anyone points out the philosophy behind this.