Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: a problem in trying to use unsigned varaibles

Author: Uri Blass

Date: 08:55:42 09/24/03

Go up one level in this thread


On September 24, 2003 at 09:40:17, Uri Blass wrote:

>On September 24, 2003 at 09:01:12, Tim Foden wrote:
>
>>On September 24, 2003 at 07:43:33, Uri Blass wrote:
>>
>>>I was told that unsigned varaibles are better to use in every case that I can do
>>>it.
>>>
>>>one of the varaibles that cannot get negative value is the ply of the search but
>>>the problem is that this varaible is connected with beta because I tell movei
>>>always that beta cannot be more than 9999-ply
>>>
>>>How do you solve that problem?
>>>
>>>practically I was too lazy to replace all my varaibles and decided only to
>>>replace few varaibles and remember that rule for new varaibles.
>>>
>>>It was another varaible that I defined as unsigned and was connected with ply
>>>and when I got the warning
>>>signed/unsigned mismatch I tried to change ply to be unsigned and got more
>>>warning of the same kind because beta is unsigned.
>>
>>How can beta be unsigned?  It doesn't seem to make sense to be to have an
>>unsigned beta.  Maybe you meant to say signed here?
>
>You are right
>
>beta is signed when ply is unsigned or should be unsigned.
>>
>>>
>>>I can get rid of the warning by adding signed.
>>>
>>>if (beta>9999-(signed)ply)
>>>		beta=9999-(signed)ply;
>>>
>>>I doubt if it is a good idea and it is possible that the conversion is going to
>>>cost time for the computer.
>>
>>No, AFAIK, it should not cost any time in this case.  It just changes the way
>>the compiler thinks about the ply value.  It doesn't actually convert a value
>>from unsigned to signed.  It just causes the value to be interpreted as signed
>>where it was previously interpreted as being unsigned.
>>
>>Cheers, Tim.
>
>Thanks.
>I guess that you are right.
>I had no idea about the way that the computer works and I thought it may need
>more time to use value as signed when it usually use it as unsigned.
>
>Uri



I decided to keep it int and not unsigned int because I found that int is
slightly faster.

Maybe it is a random compiler optimization but I suspect that it is possible
that the compiler can do some optimization that it cannot do when there is a
casting to signed int in part of the cases.

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.