c myassert code example

Example 1: assert() in c

(Assert Truth of Expression) In the C Programming Language,
assert is a macro that is designed to be used like a function.

Following is syntax for assertion:
			void assert( int expression ); 
            
Case I  : WHEN expression EVALUATES true,
		  nothing happens and the compiler proceeds to execute successive
          statements
Case II : WHEN expression EVALUATES false,
	      the expression, sourcecode filename, and line number are 
          sent to the standard error, and then abort() function is called.

Example 2: c++ assert

static_assert(sizeof(long) == 8, "long must be 8 bytes");
static_assert(sizeof(int) == 4, "int must be 4 bytes");
 
int main()
{
	return 0;
}

Tags:

Cpp Example