K&R App A, par. 8 & 8.2, on Declarat - (nf)
jim at ism780b.UUCP
jim at ism780b.UUCP
Wed Aug 1 14:26:15 AEST 1984
#R:log-hb:-18000:ism780b:25500002:000:686
ism780b!jim Jul 13 19:35:00 1984
> I agree that "a = 1;" should be a valid global declaration, but see
> nothing wrong with it as a local one. The statements "int a=1;"
> "int a; a = 1;" and "a = 1;" should all produce equivalent code!
> This is because of the way C handles initialization of automatic
> local variables. The only problem I can see is in letting the
> compiler tell where the declarations end and the statements begin.
> If you allow this as a valid declaration, that's not a problem.
int a = 2;
main() {
a = 1;
x();
}
x() {
printf("%d\n", a);
}
will print "2" if "a = 1" is a declaration,
"1" if it is an assignment (current, expected, behavior).
-- Jim Balter, INTERACTIVE Systems (ima!jim)
More information about the Comp.lang.c
mailing list