## For instruction on writing tutorials ## http://www.ros.org/wiki/WritingTutorials #################################### ##FILL ME IN #################################### ## for a custom note with links: ## note = ## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links ## note.0= [[ecl_errors/Tutorials/Error Handling in the Ecl|Error Handling]] ## descriptive title for the tutorial ## title = Assertions in the Ecl ## multi-line description to be displayed in search ## description = how to utilise ecl's run-time and compile-time asserts/aborts. ## the next tutorial description (optional) ## next = ## links to next tutorial (optional) ## next.0.link= ## next.1.link= ## what level user is this tutorial for ## level= BeginnerCategory ## keywords = ecl errors assertions #################################### <<IncludeCSTemplate(TutorialCSHeaderTemplate)>> == Run-Time Assert/Abort == These functions, because they are coupled with fallback macros for debug/ndebug modes, are the only functions in the ecl not namespaced inside the ecl namespace. Rather they are prefixed with ecl_. The `ecl_run_time_assert` macro/function is a tool for conditional testing. It is governed by the presence of the `NDEBUG` macro. If `NDEBUG` is absent (either in your code or c-flagged by the compiler (`-DNDEBUG`) then run_time_assert will equate to a macro that defers to a null function pointer. This is the fastest means of bypassing debugged code. If `NDEBUG` is defined, then `ecl_run_time_assert` will act as a conditional test via a function. If the test fails, it will output some data (that you have passed to the function) before finally aborting. {{{ #!cplusplus int i = 3; int j = 2; ecl_run_time_assert(i < j, LOC, "Illegal context, need i < j"); }}} The `ecl_runtime_abort` macro/function works similarly except that it does no conditional test and it is not negated by the presence of `NDEBUG`. === Compile-Time Assert === There is also a macro which works as a compile time equivalent of `ecl_run_time_assert()`. This macro is useful for checking template parameters mostly. When passed a logical condition which fails, an eye-catching COMPILE_TIME_FAILURE is reported in the compile log. {{{ #!cplusplus ecl_compile_time_assert( 1 > 3 ) }}} Corresponding failure is reported in a format similar to the example output shown below: {{{ #!cplusplus test.cpp:47: error: invalid application of ‘sizeof’ to incomplete type ‘COMPILE_TIME_FAILURE<false>’ }}} ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## FILL IN THE STACK TUTORIAL CATEGORY HERE