Device Monitoring Studio - Monitor, log and analyze data coming through PC ports and connections

$assert Directive


$assert(condition-expression [, message [, fatal-expression]]);

Assert directive is evaluated at run-time. First, condition-expression is evaluated. If it evaluates to non-zero value, nothing happens. But if it evaluates to a zero value, message is displayed to the user and structure binding is terminated. If message is omitted, standard “Assertion Failed” message is displayed. message, if present, must be a string expression. fatal-expression, if present, must be a constant expression. If it evaluates to a non-zero value, the assertion is fatal (this is a default behavior), that is, fired assertion terminates structure binding. If it evaluates to zero, assertion is only informational.

Assertions are good at verifying whether the data structure is being bound to correct data.

struct A
    int a;
    $assert(5 < a && a < 10,"a must be between 5 and 10");