Thursday, February 28, 2008

Assertion statements

Symbian OS C++ has some nice assertion macros (__ASSERT_ALWAYS() and __ASSERT_DEBUG()). These can be used to make assertions in your code. Being more clear: To ensure that an expression is true (e.g. a pointer is valid). This expression is placed in the first argument of the assertion. The second argument specifies what is performed when the assertion evaluates to false. Here you can place a panic calling function or throw an exception or do whatever you want. Good style is not to place code with sideeffects into an assertion. That means neither the left value nor a right value within the expression is changed. E.g. an evaluation is an expression without sideeffects wereas an assignment is an expression with a sideeffect to the left value.

The assertion macros can be easily coded for usage on other platforms which use C++.