On 1/29/09, Per Inge Mathisen <[email protected]> wrote: > I want to define a new macro ASSERT_RETURN(expr, retval, ...) that > asserts in debug builds, and returns with the given return value in > non-debug builds. This to make it easier to do the right thing when > coding, which is to first check an entry condition with an assert, and > then check it again to return on failure. It also has the added > benefit that it will only evaluate the expression once, unlike > ASSERT(expr); if (!expr) ... code, since even in non-debug builds we > evaluate the expression to output logging in case of error. > > An example: ASSERT_RETURN(false, 1, "testing"); > > This macro will test the expression 'false' and if it fails (always) > it will assert, if asserts are enabled, and if not (or if continue > from gdb is used) return 1. > > Since we have had quite a few rounds on the exact definition of the > ASSERT macro, please have a close look at this patch. > > > - Per >
This could be very useful. I was thinking we may do something like a ASSERT_ENTER() as well, to catch input errors, but that would be much harder to determine a valid range for some of the input parameters. (was thinking about the signed/unsigned U/BYTE/WORD/LONG conversions as well. We still need to find those suckers) _______________________________________________ Warzone-dev mailing list [email protected] https://mail.gna.org/listinfo/warzone-dev
