rmariani@watmum.UUCP (12/04/86)
Watch out for this one folks... it bit me pretty hard
In a for loop where the initialiation is constant
e.g.
for (i=0;i<200;i++) { ... }
The good folks at Aztec do the initial check at compile time and
determine that the test can be made at the end of the loop thus
saving a branch.
The machine code looks like this
set i=0
LOOP
do the code
increment i
compare against 200
branch if less than to the LOOP
This is swell... however it isn't smart enough, on a loop like this
for (i=200;--i>=0;) { ... }
It generates code of the same form!!!!! but that means that the
first time it enters the loop i=200!!!!! That's wrong! They're
gonna have to be smart enough to take side effects in the conditional
into consideration.
If you want to see the exact problem just compile the following:
main()
{
int i;
for (i=20;--i>=0 ;)
printf("%d\n",i);
}
And note the results (20 is printed, it shouldn't be), then compile again with
the -A and -T options and look at the assembler it generated
Is there an Aztec beta tester listening??? Please, please have them fix this
for version 3.40. Let me know if you read this and you're someone who can do
something about it... tell me who to write to... anything...
-Rico
...watmath!watmum!rmariani
page@ulowell.UUCP (Bob Page) (12/05/86)
rmariani@watmum.UUCP (Rico Mariani) wrote in article <716@watmum.UUCP>: > for (i=20;--i>=0 ;) > printf("%d\n",i); >And note the results (20 is printed, it shouldn't be) I just tried this under 3.30e (beta version), and it behaves properly; the first thing printed was '19'. ..Bob -- Bob Page, U of Lowell CS Dept. ulowell!page, page@ulowell.CSNET