Recently, a friend of mine showed to me very naive code.
#include "stdio.h"
{
int count = 0;
while ( count < 8 )
{
printf("%d %d",count,count++);
}
return 0;
}
Simple, and I was tricked into answering :
0 0
1 1
2 4
...
Well, not quite true, it turned out it is evaluated from right to left in C ( printf is a procedural call, after all ). It caught me really off guard for such a problem. After researching awhile, PERL seems to react the same. But not for PHP. No tests for JAVA and javascript yet. All of the tests are done on an IntelX86 machine.
Now that makes me think what could be the cause of such eerie results. No idea. I thought it could have been compiler differences, conventions. I talked this with a friend of mine, and interesting we find that the gcc compiler with the -Wall option on, yields this :
a.c: In function `main':
a.c:8: warning: operating on `count' may be undefined
a.c:8: warning: operating on `count' may be undefined
Well, he later gave me a link of this :
http://www.ddj.com/dept/cpp/184403851/
Problem solved? Guess so...? I still cannot answer what is for PERL and PHP though.
1 comment:
太刺激了
眼睛受不了
你还是换个背景色吧 :)
Post a Comment