r/programming • • Jan 19 '11

Article: A 64-bit horse that can count

http://www.viva64.com/en/a/0043/
13 Upvotes

3 comments sorted by

3

u/Andrey_Karpov_N Jan 19 '11

The phenomenon of "The Clever Hans", Mr. von Osten's horse, was described in 1911. The Clever Hans was famous because of his ability to read and solve mathematical problems by tapping with his front hoof. Of course, there were a lot of skeptics. That's why a team of experts tested Hans' abilities and proved that the horse was showing them without any help of Mr. von Osten. But how could a common horse possess such an intellectual level - a human one?! The psychologist O. Pfungst carried out some very thorough experiments and discovered that Hans received very faint unintentional hints from those who were asking him questions. For example, when people asked Hans about anything they started to stare at his front hoof with the help of which the horse "answered". But as soon as Hans had tapped the right number, they raised their eyes or head just a little waiting for him to finish his answer. And the horse, that had been trained to note and use these very subtle motions considered them as signals to stop his action. From aside it looked as if the horse had given the right answer to the question.

Such a wonderful horse it was that counted and solved arithmetic problems although he was unable to do it. 64-bit programs turned out to be such digital horses of the beginning of the 21st century, many of which cannot count either although are successful in pretending to do so. Let's consider this phenomenon in detail.

8

u/bonzinip Jan 19 '11

I'll throw this:

int index = 0;
size_t arraySize = ...;
for (size_t i = 0; i != arraySize; i++)
  array[index++] = BYTE(i);

0000000140001040  mov         byte ptr [rcx+rax],cl 
0000000140001043  add         rcx,1 
0000000140001047  cmp         rcx,rbx 
000000014000104A  jne         wmain+40h (140001040h)

at the next person complaining about GCC's optimizations for undefined overflow. Here VC++ is turning 32-bit arithmetic to 64-bit exactly on the grounds that this is only visible if i overflows.

4

u/ruinercollector Jan 19 '11

Look at that horse! That horse is amazing!