Bitwise and in an if statement?

This is a discussion on Bitwise and in an if statement? within the C++ Programming forums, part of the General Programming Boards category; Why does this code produce errors?: Code: if (CLS_COLOR & clsmode) { clsflags += GL_COLOR_BUFFER_BIT; } error C2143: syntax error ...

  1. #1
    JMK
    JMK is offline
    Registered User
    Join Date
    May 2010
    Posts
    24

    Bitwise and in an if statement?

    Why does this code produce errors?:
    Code:
            if (CLS_COLOR & clsmode)
            {
                clsflags += GL_COLOR_BUFFER_BIT;
            }
    error C2143: syntax error : missing ')' before ';'

  2. #2
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    265
    That if statement should be valid. Do you have more code?

  3. #3
    JMK
    JMK is offline
    Registered User
    Join Date
    May 2010
    Posts
    24
    No. MSVC also says:
    empty controlled statement found; is this the intent?
    CLS_COLOR is a constant.
    #define CLS_COLOR 1;
    Last edited by JMK; 09-21-2010 at 06:21 PM.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    242
    I bet it's just checking to make sure you didn't mean && in this context. If so, I actually kind of like the warning. I don't see anything wrong with your code, though.

  5. #5
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    265
    Ah! Remove the semi-colon from the macro. Should be:

    Code:
    #define CLS_COLOR 1

  6. #6
    JMK
    JMK is offline
    Registered User
    Join Date
    May 2010
    Posts
    24
    Oh god. :|

    Thanks.

Popular pages Recent additions subscribe to a feed

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