[ Previous | Next | Contents | Home | Search ]
AIX Version 4.3 Understanding the Diagnostic Subsystem for AIX

Message Handling

In general, there should be no printf() or fprintf() calls imbedded in TU code which is delivered for production use. This includes debug messages, execution-progress messages, and so on. However, it is understood that such practices are common and useful during the initial code development, and sometimes desirable at a later time when something breaks. Therefore, to satisfy both requirements, the messages should be allowed to be conditionally compiled in and out of the code. To allow the calling application to redirect the messages to any file, including stdout, only the fprintf() call should be used. Then, to conditionally compile the messages, the following convention should be followed:

In one of the include files, define the following PRINT macros conditionally with the standard conditional flag TU_DEBUG_MSG.

           #ifdef TU_DEBUG_MSG
           #define PRINT( args ) fprintf args
           #define PRINT( args )

Next, use the "msg_file" pointer in the TUCB structure definition which determines where messages will be sent.

Then, at any place in the code where a message should be output, use the PRINT macro. The calling application would then set the "msg_file" parameter to stdout in order to have messages directed to a terminal or monitor. Alternatively, to have messages directed to a file, the calling application would use the fopen() function to open a file and set "msg_file" to the pointer returned from this call.

For example, you want to print the message "Hello, World number 1", and tucb_ptr is a pointer to the TU_TYPE structure passed by the application, and w_num is a variable with a value of 1. You could then insert, at an appropriate place in the TU code, a line like the following:

PRINT((tucb_ptr->parms.msg_file, "Hello, World number %d",w_num));
Note: The double parentheses are required to pass variable-length argument lists through the PRINT macro to the fprintf() function.

[ Previous | Next | Contents | Home | Search ]