5.8.2 Using Constructors and Destructors

C++ constructors are called to initialize class objects when those objects are created, and destructors are invoked when class objects are destroyed. For automatic (that is, local, non-static) variables that contain constructors and destructors, the constructor is called when the variable comes into scope and the destructor is called when the variable goes out of scope. However, when you call the tpreturn() or tpforward() function, the compiler performs a non-local go to (using longjmp(3)) such that destructors for automatic variables are not called. To avoid this problem, write the application so that you call tpreturn() or tpforward() from the service routine directly (instead of from any functions that are called from the service routine). In addition, one of the following should be true:

  • The service routine should not have any automatic variables with destructors (they should be declared and used in a function called by the service routine).
  • Automatic variables should be declared and used in a nested scope (contained within curly brackets {}) in such a way that the scope ends before calling the tpreturn() or tpforward() function.

In other words, you should define the application so that there are no automatic variables with destructors in scope in the current function or on the stack when the tpreturn() or tpforward() function is called.

For proper handling of global and static variables that contain constructors and destructors, many C++ compilers require that you compile main() using the C++ compiler.

Note:

Special processing is included in the main() routine to ensure that any constructors are executed when the program starts and any destructors are executed when the program exits.

Because main() is provided by the Oracle Tuxedo system, you do not compile it directly. To ensure that the file is compiled using C++, you must use the C++ compiler with the buildserver command. By default, the buildserver command invokes the UNIX cc command. You can specify that the buildserver command invoke the C++ compiler, instead, by setting the CC environment variable to the full path name for the C++ compiler. Also, you can set flags for any options that you want to include on the C++ command line by setting the CFLAGS environment variable. For more information, refer to Setting Environment Variables.