CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Join Date
    Mar 2009
    Posts
    94

    Re: If Statement && Help

    Quote Originally Posted by KingTermite View Post

    if ( (GetAsyncKeyState(VK_F8) && x ) > 1)
    Would this ever be true? I think (a && b) returns either 0 or 1, never >1.

  2. #17
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: If Statement && Help

    Quote Originally Posted by KingTermite View Post
    is this supposed to be:

    if ( (GetAsyncKeyState(VK_F8) && x ) > 1)

    or

    if (GetAsyncKeyState(VK_F8) && (x > 1) )

    Compiler probably doesn't know? You have two evaluations there.
    That wouldn't be ambiguous to the compiler.

  3. #18
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: If Statement && Help

    Quote Originally Posted by GCDEF View Post
    That wouldn't be ambiguous to the compiler.
    Neither one is ambiguous to compiler. For the programmer – may be.
    Compare operators have higher precedence than logical AND.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  4. #19
    Join Date
    Apr 2008
    Posts
    725

    Re: If Statement && Help

    Quote Originally Posted by w3rd View Post
    Would this ever be true? I think (a && b) returns either 0 or 1, never >1.
    I thought a && b returns true or false. i'm not sure that true is equivalent to 1

  5. #20
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: If Statement && Help

    Quote Originally Posted by Amleto
    I thought a && b returns true or false.
    That is true in C++.

    Quote Originally Posted by Amleto
    i'm not sure that true is equivalent to 1
    true is converted to 1.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured