for != while

karl at haddock karl at haddock
Tue Sep 2 06:53:00 AEST 1986


It's well known that the equivalence between for and while breaks down if
there's a "continue" statement.  Here's another case I just discovered:

main() {
	char *foo = "outer";
	for (;; printf(foo),exit(0)) {
		char *foo = "inner";
	}
}

This prints "outer" (vax SVR2 compiler), though the for-while equivalence
might lead one to expect "inner".

Karl W. Z. Heuer (ima!haddock!karl, karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list