K
Keith Thompson
santosh said:Default said:Kenneth said:santosh wrote:
Though Turbo C++ 3.0, which the OP uses, is not given, it's 1.0
version is provided and it exhibits the same bug. The C compiler
however is correct. I wonder for how many more rarely used
constructs like these, they trip up on? Maybe, they didn't do all
the rigorous software testing that's done these days.
Does the bug only occur with "for(;0"? What about:
for ( ; a>b ; )
printf("Yup, the bug is still here.\n");
return(0);
}
That's a good question. What about something like:
char s[] = "";
for(;*s
printf("Yup, the bug is still here.\n");
The "bug" doesn't appear, both for global and local s.
That seems common enough that it should have turned up in common usage.
The bug seems to be produced only with a numeric literal. There may be
other possibilities too, but whose's going to bother testing
exhaustively such an outdated compiler/s.
I'll bet it's an optimization gone awry. The author(s) probably tried
to optimize the case of a constant condition and got the logic
backwards.
I wonder whether "for (;1" also misbehaves.