Jump to content

SOM Assert: Difference between revisions

From EDM2
Created page with "This macro asserts that a boolean condition is true. ==Syntax== <PRE> boolean condition; long errorCode; SOM_Assert(condition, errorCode); </PRE> ==Parameters== ;..."
 
Ak120 (talk | contribs)
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
This macro asserts that a boolean condition is true.  
{{DISPLAYTITLE:SOM_Assert}}
This macro asserts that a boolean condition is true.


==Syntax==
==Syntax==
<PRE>
boolean    condition;
boolean    condition;
long      errorCode;
long      errorCode;
 
SOM_Assert(condition, errorCode);
SOM_Assert(condition, errorCode);
</PRE>


==Parameters==
==Parameters==
; condition (boolean) : A boolean expression that is expected to be TRUE (nonzero).  
;condition (boolean): A boolean expression that is expected to be TRUE (nonzero).
 
;errorCode (long): The integer error code for the error to be raised if condition is FALSE.
; errorCode (long) : The integer error code for the error to be raised if condition is FALSE.  


==Return Code==
==Return Code==


==Remarks==
==Remarks==
The SOM_Assert macro is used to place boolean assertions in a program:  
The SOM_Assert macro is used to place boolean assertions in a program:
* If condition is FALSE, and errorCode indicates a warning-level error and SOM_WarnLevel is set to be greater than zero, then a warning message is output.  
* If condition is FALSE, and errorCode indicates a warning-level error and SOM_WarnLevel is set to be greater than zero, then a warning message is output.
* If condition is FALSE and errorCode indicates a fatal error, an error message is output and the process is terminated.  
* If condition is FALSE and errorCode indicates a fatal error, an error message is output and the process is terminated.
* If condition is TRUE and SOM_AssertLevel is set to be greater than zero, then an informational message is output.  
* If condition is TRUE and SOM_AssertLevel is set to be greater than zero, then an informational message is output.


'''External (Global) Data'''  
'''External (Global) Data'''
   long SOM_WarnLevel;  /* default = 0 */
   long SOM_WarnLevel;  /* default = 0 */
   long SOM_AssertLevel; /* default 0 */
   long SOM_AssertLevel; /* default 0 */


==Expansion==
==Expansion==
If condition is FALSE, and errorCode indicates a warning-level error and SOM_WarnLevel is set to be greater than zero, then a warning message is output. If condition is FALSE and errorCode indicates a fatal error, an error message is output and the process is terminated. If condition is TRUE and SOM_AssertLevel is set to be greater than zero, then an information message is output.  
If condition is FALSE, and errorCode indicates a warning-level error and SOM_WarnLevel is set to be greater than zero, then a warning message is output. If condition is FALSE and errorCode indicates a fatal error, an error message is output and the process is terminated. If condition is TRUE and SOM_AssertLevel is set to be greater than zero, then an information message is output.


==Example Code==
==Example Code==
Line 40: Line 38:


==Related==
==Related==
===Macros===
;Macros
* SOM_Expect  
* SOM_Expect
* SOM_Test  
*[[SOM_Test]]
* SOM_TestC  
*[[SOM_TestC]]
[[Category:SOM Kernel]]
 
[[Category:SOM macro]]

Latest revision as of 16:27, 17 December 2022

This macro asserts that a boolean condition is true.

Syntax

boolean    condition;
long       errorCode;

SOM_Assert(condition, errorCode);

Parameters

condition (boolean)
A boolean expression that is expected to be TRUE (nonzero).
errorCode (long)
The integer error code for the error to be raised if condition is FALSE.

Return Code

Remarks

The SOM_Assert macro is used to place boolean assertions in a program:

  • If condition is FALSE, and errorCode indicates a warning-level error and SOM_WarnLevel is set to be greater than zero, then a warning message is output.
  • If condition is FALSE and errorCode indicates a fatal error, an error message is output and the process is terminated.
  • If condition is TRUE and SOM_AssertLevel is set to be greater than zero, then an informational message is output.

External (Global) Data

  long SOM_WarnLevel;   /* default = 0 */
  long SOM_AssertLevel; /* default 0 */

Expansion

If condition is FALSE, and errorCode indicates a warning-level error and SOM_WarnLevel is set to be greater than zero, then a warning message is output. If condition is FALSE and errorCode indicates a fatal error, an error message is output and the process is terminated. If condition is TRUE and SOM_AssertLevel is set to be greater than zero, then an information message is output.

Example Code

#include <som.h>
main()
{
   SOM_WarnLevel = 1;
   SOM_Assert(2==2, 29);
{

Related

Macros