Common Template Migration Syntax Changes

You must use the keyword typname to distinguish types in template code in HP aC++. Also, use the this->notation to reference data members.

The cfront Implicit Include Convention

The preferred method for specifying template declarations and definitions in HP aC++ is to put declarations and definitions in the same file.

In HP C++ (cfront), for any .h file that contains template declarations, there is a .c file that contains definitions for those templates.

HP aC++ provides the following options to ease migration from HP C++ (cfront):

+inst implicit_include: This option instructs the compiler to use the cfront default file, name lookup, for template definition files.

+inst include_suffixes: Use this option to replace the cfront -ptS"list"option. This specifies file name extensions for template definition files.

Converting Directed Mode to Explicit Instantiation

If you use directed mode instantiation with the cfront based compiler, an awk script can be used to convert your file to an instantiation file that uses the explicit instantiation syntax:

Example:

#!/usr/bin/ksh

#For a Directed-Mode Instantiation file that is the parameter

#to the script, create a file that can be compiled with the

#aC++ compiler using the Explicit Instantiation Syntax.

#(Note that this will only work for classes.)

closure_file=$1

closure_file_base_name=${1%\.*}

eis_file=$closure_file_base_name.eis.C

print “Output file: $eis_file”

# Get all of the include directives.

grep “#include” $closure_file > /tmp/dmi2eis1.$$

#Collect all of the Directed-Mode Instantiation directives. grep -v “#include” $closure_file \

grep -e “>” -e “<“ \ grep -v “(“ \

awk ‘ {if ($1 != “//”) {print $0;} }’ >/tmp/dmi2eis2.$$

#Print the line assuming that the last element is the variable

#name followed immediately by a semi-colon.

awk ‘{ n=split($0,sp0); printf(“template class”); for (i=1; i<=(n-1); i++) {

printf(“ %s”, sp0[i]);

}

printf(“;\n”);

}’ < /tmp/dmi2eis2.$$ > /tmp/dmi2eis3.$$

cat /tmp/dmi2eis1.$$ /tmp/dmi2eis3.$$ > $eis_file rm -f /tmp/dmi2eis*.$$

NOTE: You can use explicit instantiation to instantiate a template class and all its member functions, an individual template function, or a member function of a template class.

220 Migrating from HP C++ (cfront) to HP aC++

Page 220
Image 220
HP C/aC++ for PA-RISC Software manual Common Template Migration Syntax Changes, Cfront Implicit Include Convention