Author: Miguel A. Ballicora
Date: 13:09:54 01/10/03
Go up one level in this thread
On January 10, 2003 at 15:47:24, Dieter Buerssner wrote: >On January 10, 2003 at 15:16:52, Uri Blass wrote: > >>2)I tried a code of dieter and got warning from the compiler(see the bottom of >>this post for that code) >> >>warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned long ', >>possible loss of data > >I consider the warning is bogus. The mask at the end guarantees, that exactly 32 >bits are used, and unsigned long is at least 32 bit. So it can never lose any >data. You can get rid of the warning by some casts - but they change exactly >nothing otherwise ... Actually, the loss of data is intended, we want to lose the upper 32 bits :-) As you say, we lost them after the mask and before the conversion, though. Yes, the warning is bogus and annoying, but it is for an experienced programmer like you Dieter. I suggest to Uri, who is learning C, to be extra cautious and pay attention to it. Once he is sure that he knows what he is doing, he can add the typecast. It helped me when I started to learn C (I am still learning...). Miguel > >>Note that I changed >>int PopCount(unsigned long long a) >>to >>int PopCount(BitBoard a) >> >>I also have in my code >>typedef unsigned __int64 BitBoard; >> >>I also never use the word long in my program except the code that I copied from >>Dieter and I use int for 32 bit numbers. >> >>The warning was about w= >> >>int PopCount(BitBoard a) >>{ >> unsigned long w; >> int n = 0; >> w = a&0xffffffffUL; > > w = (unsigned long)(a&0xffffffffUL); > >> if (w) >> do >> { >> n++; >> } >> while ((w &= w-1) != 0); >> w = (a>>32)&0xffffffffUL; > w = (unsigned long)((a>>32)&0xffffffffUL); >> if (w) >> do >> { >> n++; >> } >> while ((w &= w-1) != 0); >> return n; >>} > >Regards, >Dieter
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.