C++ type decoration

The names of C++ functions can be overloaded. Two C++ functions with the same name can coexist if they have different arguments. C++ compilers type-decorate or 'mangle' function names by default. The type-decorated name consists of argument type names that are appended to their function names.

The names of C++ functions can be overloaded. Two C++ functions with the same name can coexist if they have different arguments, for example the first func function takes an integer type argument while second func function takes character type argument:
   int func( int i )
   int func( char c )
C++ compilers type-decorate or 'mangle' function names by default, where the argument type names are appended to their function names, as in func__Fi and func__Fc for the two earlier examples. The mangled names are different on each operating system, so code that explicitly uses a mangled name is not portable.

On Windows operating systems, the type-decorated function name can be determined from the .obj (object) file.

With the Microsoft Visual C++ compiler on Windows, you can use the dumpbin command to determine the type-decorated function name from the .obj (object) file, as follows:
   dumpbin /symbols myprog.obj
where myprog.obj is your program object file.
On UNIX operating systems, the type-decorated function name can be determined from the .o (object) file, or from the shared library, with the nm command. The nm command can produce considerable output, so it is suggested that you pipe the output through grep to look for the right line, as follows:
   nm myprog.o | grep myfunc
where myprog.o is your program object file, and myfunc is the function in the program source file.
The output that is produced by all of these commands includes a line with the mangled function name. The following nm command output example contains the mangled function name:
   myfunc__FPlT1PsT3PcN35|     3792|unamex|         | ...

Once you obtained the mangled function name from one of the preceding commands, you can use it in the appropriate command.

When you register a routine with the CREATE statement, the EXTERNAL NAME clause must specify the mangled function name. The following example registers the mangled function name with use of the EXTERNAL NAME clause:
   CREATE FUNCTION myfunco(...) RETURNS...
          ...
          EXTERNAL NAME '/whatever/path/myprog!myfunc__FPlT1PsT3PcN35'
          ...
If your routine library does not contain overloaded C++ function names, you have the option of using extern "C" to force the compiler to not type-decorate function names. You can always overload the SQL function names that are given to UDFs since the database manager resolves what library function to call based on the function name and the parameter it takes.
#include <string.h>
#include <stdlib.h>
#include "sqludf.h"
 
/*---------------------------------------------------------------------*/
/* function fold: output = input string is folded at point indicated   */
/*                         by the second argument.                     */
/*         inputs: CLOB,                 input string                  */
/*                 LONG                  position to fold on           */
/*         output: CLOB                  folded string                 */
/*---------------------------------------------------------------------*/
extern "C" void fold(
      SQLUDF_CLOB       *in1,                    /* input CLOB to fold */
   ...
   ...
}
/* end of UDF: fold */
 
/*---------------------------------------------------------------------*/
/* function find_vowel:                                                */
/*             returns the position of the first vowel.                */
/*             returns error if no vowel.                              */
/*             defined as NOT NULL CALL                                */
/*         inputs: VARCHAR(500)                                        */
/*         output: INTEGER                                             */
/*---------------------------------------------------------------------*/
extern "C" void findvwl(
      SQLUDF_VARCHAR    *in,                     /* input smallint */
   ...
   ...
}
/* end of UDF: findvwl */

The fold and findvwl UDFs are not type-decorated by the compiler, and they must be registered in the CREATE FUNCTION statement with their plain names. Similarly, if a C++ stored procedure or method is coded with extern "C", its undecorated function name would be used in the CREATE statement.