C/C++ Programmer's Guide (G06.27+, H06.08+, J06.03+)

In the Guardian environment, Cprep truncates the UNIX named iostream header file from
iostream.h to iostreah to comply with the Guardian file naming conventions. However, for
portability, you can use iostream.h.
Interfacing to the Standard C Run-Time Library
To declare a standard C run-time library function, use the #include preprocessor directive to
include the name of the header file that contains the function prototype for the particular function.
For example:
#include <stdio.h>
Interfacing to User-Defined C Libraries
If you have user-defined C function prototypes defined in a header file, designate the header file
as having C linkage. Therefore, use the extern C construct. For example:
extern "C" {
#include "myclib.h"
}
Interfacing to User-Defined C Functions
To declare a user-defined C function, you can use the C++ extern C construct, which is a standard
C++ language feature. Here is an example of using the extern C construct to declare a user-defined
C function:
extern "C" void f(int);
If you want to declare several user-defined C functions at the same time, you can use braces. For
example,
extern "C" {
void f(int);
int g(char);
}
The extern C construct states that the specified functions are C functions so that there is no name
encoding. If you do not include the user defined C function in the extern C construct, you will get
errors when Binder tries to bind a module that contains these functions.
In C++, function names are encoded or mangled to produce unique internal names, which
incorporate function argument types. In C there is no name encoding. Therefore, if you want to
call a C function, its name will not be the same as that produced by the C++ translator and used
by the Binder. To indicate that C linkage applies, rather than C++, you must use the extern C
construct.
Interfacing to NonStop SQL/MP
Cfront does not support embedded SQL. Embedded SQL support is provided by binding in C
modules containing the desired SQL statements. Keep all SQL statements in one or more separately
compiled C modules and bind these C modules into the executable C++ object file with Binder.
HP Specific Features for the Guardian Environment
The HP specific features discussed in this subsection are applicable to only the Guardian
environment.
Mixed-Language Programming
Mixed-language programming in the HP environment comprises invoking a C, COBOL85,
FORTRAN, Pascal, or TAL routine from your C++ program, or calling a C++ function from one of
these other languages. A function declaration must always precede any invocation of that function.
For information on interfacing to other languages, refer to the discussion on mixed-language
programming in Chapter 7: Mixed-Language Programming for TNS Programs, and in Chapter 8:
Mixed-Language Programming for TNS/R and TNS/E Native Programs.
HP Specific Features for the Guardian Environment 419