'<' : unsafe use of type 'bool' in operation

This is a discussion on '<' : unsafe use of type 'bool' in operation within the C++ Programming forums, part of the General Programming Boards category; Code: Assert( uAddress < VMM_MEM, "AddProperty: Invalid address" ); This isn't anything to worry about is it?...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    '<' : unsafe use of type 'bool' in operation

    Code:
    Assert( uAddress < VMM_MEM, "AddProperty: Invalid address" );
    This isn't anything to worry about is it?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    It might be. What's the context, and the exact compiler warning?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Context might be helpful -- like the declaration of Assert, the type of uAddress, the value of VMM_MEM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    As in:

    Code:
    void VMMemory::Write( unsigned uAddress, DWORD dwVal )
    {
        Assert( uAddress < VMM_MEM, "Invalid address for VM memory write" );
    
        *( m_dwMemory + uAddress ) = dwVal;
    }
    Assert is defined as:

    Code:
    // I pass false or true to AssertDialog here instead of bExpr to avoid a 4800 warning
    // This should improve performance too, judging by the actual warning message
    #define Assert( bExpr, szErrText ) ( !bExpr ) ? AssertDialog( false, ##szErrText ) : AssertDialog( true, "" );
    AssertDialog is your bog standard Win32 Dialog launcher (DialogBox()) and also takes care of some other stuff.

    Code:
    void AssertDialog( bool bEval, const char* szExprText );
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by ahluka
    Assert is defined as:

    Code:
    // I pass false or true to AssertDialog here instead of bExpr to avoid a 4800 warning
    // This should improve performance too, judging by the actual warning message
    #define Assert( bExpr, szErrText ) ( !bExpr ) ? AssertDialog( false, ##szErrText ) : AssertDialog( true, "" );
    Lacking parentheses, can you take a guess at the expansion? Hint:
    Code:
    !uAddress < VMM_MEM
    And I doubt you want to have the habit of terminating a macro with a semicolon.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Yay fixed it - the warning at least.

    You meant this right?

    Code:
    #define Assert( bExpr, szErrText ) ( !(bExpr) ) ? AssertDialog( false, ##szErrText ) : AssertDialog( true, "" );
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    I'd remove the trailing semicolon, and why are you using ##?

    [edit]What would be wrong with this?
    Code:
    void Write( unsigned uAddress, DWORD dwVal )
    {
       AssertDialog( uAddress >= VMM_MEM, "Invalid address for VM memory write" );
       // ...
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Absolutely nothing at all. T'is a good idea - thankies
    Plus it removes the ambiguation between the standard library Assert macro - my IDE displays two when I type the opening parenthesis. Not a problem, just annoying.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 04:34 PM
  4. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  5. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 04:20 PM

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