Compiler warning with bitwise operators

  • Thread starter Thread starter cody
  • Start date Start date
C

cody

I get a compiler warning with this statements:

ulong versionHash=0;
if (User!=null)
versionHash |= (ulong)User.UserID;

The warnign is like that (translated from german): "Bitwise OR-operator is
used for signed operand. It is recommended to convert a smaller unsigned
type first."

I don't understand what the compiler will tell me with that. I see no
problem since both operands are the same size and unsigned.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu
[noncommercial and no ****ing ads]
 
here is the msdn compiler warning page for the below warning

http://msdn.microsoft.com/library/d...n-us/cscomp/html/vcerrCompilerErrorCS0675.asp

The basic jist of the error is that you are telling the compiler to
sign extend the value (User.UserID) to the same size as a ulong. If
(User.UserID) is negative the extened bits are set to '1', if the
(User.UserID) us positive the extened bits are set to '0'.


If (User.UserID) is an int the below code should work
ulong versionHash=0;
if (User!=null)
versionHash |= (uint)User.UserID;

best of Luck


Andy Renk
junker_mail(remove)@yahoo.com // take out the "(remove)" to email
 
Back
Top