C4554 Warning, check operator precedence for possible error

This is a discussion on C4554 Warning, check operator precedence for possible error within the C++ Programming forums, part of the General Programming Boards category; Hi. Hope someone could shed some light on this. I have this line in code: Code: (s&DisplayPixelFormat.dwBBitMask == DisplayPixelFormat.dwBBitMask) Compiler ...

  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
    21,915
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 03: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, 03:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21