New types declared in C may be used in the language binding generated by
TAC. In this case a special description file for TAC must be written
and the newtypes key of the Define-TAC-Interface is
required. As an example, the definition of paiObject used in the
PIF database interface is described. TAC parses the TAC definition
file shown in Listing 6.2 to get the information about the new C
types.
In this case the C type paiObject can be represented by the TAC
tac::IntegerParam (see Section 8.4) which is used for
binding of integer values with a maximum size of 32 bits. This feature of
defining new C types for TAC binding is very useful because it allows
prototyping in C and minimizes the required work to bind a function to
FORTRAN. If a definition is made once it can be made available to other
TAC definitions by the depends key from the
Define-TAC-Interface. The class hierarchy is shown in
Table 8.3. A typical example of using TAC for binding a
C function to FORTRAN is shown in Figure 6.10.
Abbildung 6.10: TAC documented C for binding
This example has been taken from the PifApplicationInterface project which implements the PIF database. The documentation key fortran-name is required because there is no save method to generate a unique FORTRAN SUBROUTINE name from a C function name. The corresponding FORTRAN routine named PVSTM is shown in Figure 6.11.
Abbildung 6.11: FORTRAN function created by TAC
This function is coded in C but has a function name which can be called directly from FORTRAN. The binding always creates a SUBROUTINE because this avoids problems with FORTRAN functions returning strings which are very system dependent. The C function may or may not have a return value which is added as additional output parameter. All parameters are converted automatically to their corresponding C types. An additional error parameter is added as last parameter indicating whether the function call succeeded. After successful execution the value of this parameter is set to `1' otherwise `0' is returned.