Subj : Re: any function to handle this kind of counting? To : comp.programming From : Gerry Quinn Date : Tue Aug 02 2005 02:06 pm In article <1122914980.339356.286660@f14g2000cwb.googlegroups.com>, robert.thorpe@antenova.com says... > Gerry Quinn wrote: > > ASSERT( nums.size() == lets.size() ); > > The above is fine if you use a Microsoft C++ compiler. > > In standard C++ there is no function or macro called "ASSERT", there is > a macro called "assert". True. I did say the code was untested and it was by way of illustrative code anyway. The 'ASSERT' should be taken as something that it would be second nature for a programmer to check; it also functions as a sort of comment on the expected data. > The two do opposite things: > > In debug builds "ASSERT" will bomb if the condition in parens is true. Not so. ASSERT, like assert, bombs in debug if the condition is false. That's the only sensible action - you are 'asserting' the truth of the condition. > In debug builds "assert" will bomb if the condition in parens is not > true. > Neither are compiled in release builds. Indeed. One can use the format: if ( fail_condition ) { ASSERT( false ); // remedial or escape action for release version } ...for things that shouldn't really happen in debug or release, and need to have their causes traced in debug, but might happen in release due to some unforseeable situation, and need some defensive programming. In a game, for example, it's better that a monster sits paralysed if its pathfinding fails, rather than that the game crash or exit, so you could write: Move move = monster.SelectMove(); if ( Illegal( monster, move ) ) { ASSERT( false ); move = NULL_MOVE; } monster.SetMove( move ); That'll pick up bugs in debug, and prevent crashes in release if some get through. > I know this isn't a standard C++ only newsgroup, but I thought I would > mention the above since it's rather confusing. Not as confusing as you thought, anyway! MSVC may have its quirks, but it does not reverse the meaning of the assertion concept. - Gerry Quinn .