Thread: C4554 Warning, check operator precedence for possible error

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    17

    Question C4554 Warning, check operator precedence for possible error

    Hi. Hope someone could shed some light on this.

    I have this line in code:

    Code:
    (s&DisplayPixelFormat.dwBBitMask == DisplayPixelFormat.dwBBitMask)
    Compiler complains that:

    warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence
    But Ive tried placing them at different places, the compiler doesnt then create warnings which is good BUT say I do it like so:

    Code:
    ((s&DisplayPixelFormat.dwBBitMask) == DisplayPixelFormat.dwBBitMask)
    The compiled program only displays it correctly when I dont use any parentheses. Any ideas why? Im trying to create a "warning free" program. It displays font bitmaps onscreen. Without added parantheses theyre spaced fine, with them, and some fonts get bunched up.

    A snippet of whats before and after it:

    Code:
    for (y=y1; y<y1+HUD_FONT_HEIGHT; y++)
    	{
    unsigned short s = *(unsigned short *)(srcPtr + x*2 + y*ddsdimage.lPitch);
    if (s&DisplayPixelFormat.dwBBitMask == DisplayPixelFormat.dwBBitMask) //C4554 Warning
    	{
    	blank=0;
    	break;
    	}
    Driving me mad this warning so any help appreiciated.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Code:
    (s&DisplayPixelFormat.dwBBitMask == DisplayPixelFormat.dwBBitMask)
    is equivalent to:
    Code:
    (s & (DisplayPixelFormat.dwBBitMask == DisplayPixelFormat.dwBBitMask))
    It appears that you want the latter, and the compiler is merely warning you in case you thought differently. Consequently, you can either ignore the error, or simply clarify your intention with the parentheses, which would be the better option.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    17
    Excellent, that worked! Thanks for a speedy reply.

    I knew it was a specific placement of the parentheses, I assumed the 's' was supposed to be part of the left 'DisplayPixelFormat.dwBBitMask'.

    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM