Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: printing different values for 2 identical numbers

Author: Tim Foden

Date: 06:55:25 09/10/03

Go up one level in this thread


On September 10, 2003 at 09:36:20, Uri Blass wrote:

>On September 10, 2003 at 09:16:04, Tim Foden wrote:
>
>>On September 10, 2003 at 08:45:22, Uri Blass wrote:
>>
>>>I found that my program printed the numbers 0 and 1 when it did the following
>>>code without printing mistake or mistake1.
>>>
>>>zobpawnkey[hply]=zobpawn;
>>>if (nodes==663719)
>>>{
>>>	if (zobpawnkey[hply]!=zobpawn)
>>>		printf("mistake");
>>>	if ((zobpawnkey[hply]&1)!=(zobpawn&1))
>>>		printf("mistake1");
>>>	printf(" %d %d              ",(zobpawn&1),(zobpawnkey[hply]&1));
>>                 ^^ ^^ these expect int, not __int64.
>>
>>If using Microsoft's compiler system, you should use %I64d instead.
>>
>>Cheers, Tim.
>
>I understand that %d does not give me the right value but the fact that it
>prints different numbers for identical numbers still seems strange to me.

This can be explained.  If the number (zobpawn&1) is 1, then the stack will
contain 4 32bit int values that make up the 2 64 bit ones:

0x00000001
0x00000000
0x00000001
0x00000000

printf( "%d %d" ).  will just use the first 2 of these 32 bit numbers, thus it
will print 1 and 0.

These are the kinds of code pitfalls that are common to printf and scanf.

Cheers, Tim.
>
>Uri



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.