T_ASSERT


Name

T_ASSERT — program verification macro

Synopsis

void T_ASSERT(expression) 
int expression; 

Arguments

expression — any C expression

Return Values

None

Diagnostics

None

Description

The T_ASSERT macro is used to verify that expression evaluates to a non-zero value. If expression evaluates to 0, then T_ASSERT calls TutFatalError to print out an error message and abort. The message lists the expression that failed, the source file name, and the line number. T_ASSERT is very similar to the assert macro in <assert.h>. T_ASSERT is good for checking the validity of function arguments and return values. It is useful for doing sanity checks.

T_ASSERT is used internally in SmartSockets to verify program correctness. In the optimized versions of the SmartSockets processes and libraries, the T_ASSERT macros are compiled out. Any verification that always needs to be done is not done with T_ASSERT.

Caution

On non-ANSI-C compilers, you may experience problems using this macro if expression spans more than one line or contains string constants. The compatibility macro T_ASSERT_STR may be used instead in such instances. This macro is identical to T_ASSERT except that it does not provide the text of expression.

Examples

This example checks a value:

char *foo(ptr, positive_counter) 
struct some_struct *ptr; 
T_INT4 positive_counter; 
{ 
  char *ret_val; 
 
  T_ASSERT(ptr != NULL); 
  T_ASSERT(positive_counter > 0); 
 
/* calculate ret_val */ 
 
   return ret_val; 
} /* foo */ 
 
void bar() 
{ 
  struct some_struct *ptr; 
  char *val; 
 
  val = foo(ptr, 3); 
  T_ASSERT(val != NULL); 
} /* bar */ 

TIBCO SmartSockets™ Utilities
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com