![]() |
![]() |
|
|
Using a C++ Compiler
There are basically two differences between using a C++ compiler and a C compiler to develop application ATMI servers:
Declaring Service Functions
When declaring a service function for a C++ compiler, you must declare it to have "C" linkage using extern "C". Specify the function prototype as follows:
#ifdef __cplusplus
extern "C"
#endif
MYSERVICE(TPSVCINFO *tpsvcinfo)
By declaring the name of your service with "C" linkage, you ensure that the C++ compiler will not modify the name. Many C++ compilers change the function name to include type information for the parameters and function return.
This declaration also allows you to:
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 goto (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:
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 BEA 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.
![]() |
![]() |
![]() |
|
Copyright © 2001 BEA Systems, Inc. All rights reserved.
|