Compiler warning with bitwise operators

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cody

    Compiler warning with bitwise operators

    I get a compiler warning with this statements:

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

    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

    [noncommercial and no fucking ads]


  • Andy Renk

    #2
    Re: Compiler warning with bitwise operators

    here is the msdn compiler warning page for the below warning



    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.User ID;

    best of Luck


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

    Comment

    Working...