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

If you are migrating code from HP C++ (cfront) to HP aC++, the following list presents differences in syntax and functionality that you may need to consider. Click here for General Migration Guidelines and Tips.

NOTE: Because of incompatibilities in areas such as name mangling, libraries, and object layout, all of your C++ code for an application or library must be compiled and linked with either HP C++ (cfront) or with HP aC++. You cannot mix object files compiled with HP C++ (cfront) with those compiled with HP aC++.

For More Information


General Migration Guidelines and Tips

As you begin conversion of your HP C++ (cfront) code to HP aC++, you may want to read about the following topics:

Getting Started with Migration

  1. Compile your code with the HP C++ (cfront) compiler using the +p option. This option requests the compiler to treat anachronistic constructs as errors. Fix the anachronisms. For example:
    CC +p cfrontfile.C
    

  2. In your Makefiles:

  3. Compile and fix syntax errors.

  4. Make library changes. Begin migration to the Standard C++ Library and Tools.h++ Library.

  5. Make template changes.

    Writing Code for Both Compilers

    Use the __cplusplus macro (defined by the draft standard) to write code that can be compiled by both HP C++ and HP aC++, as in the following example:
    #if __cplusplus >= 199707L
    
       // HP aC++ code
    
    #else
    
       // HP C++ code
    
    #endif // __cplusplus >= 199707L
    

    Explicit Loading and Unloading of Shared Libraries

    HP aC++ uses system calls rather than C++ function calls to explicitly load and unload shared libraries. When migrating to HP aC++, you will need to make the following source code changes:


    Command-Line Differences

    In HP aC++, you invoke the compiler with the aCC command instead of the CC command used to invoke HP C++.

    The following sections describe differences in command-line options:

    New Command-Line Options

    New options for HP aC++ are described below. These options are not available for HP C++ (cfront), however, if a related option exists, it is noted here.

    -g0
    Replaces the -g debugger option. It generates full debug information for the debugger.

    For more information, refer to HP aC++ Debugging Options.

    +help
    Invokes this HP aC++ Online Programmer's Guide.

    +noeh
    Turns exception handling off. In HP aC++ exception handling is on by default.

    Note that in HP C++ (cfront), exception handling is off by default. To turn it on, you must use the +eh option which is obsolete in HP aC++.

    Precompiled Header File Options

    Reduce compilation time and executable file size by precompiling common include (header) files.

    Template Options
    There are new options and new functionality for template processing. For more information about HP aC++ templates, refer to:

    Obsolete Command-Line Options

    HP C++ (cfront) options that are not available in HP aC++ are listed in the following sections. If a related option exists for HP aC++, it is noted.

    Select from an Alphabetical List of Obsolete Options or a category of options:

    Alphabetical List of Obsolete Command-Line Options

    Select the option for which you want more information:

    Obsolete Debugging Option

    The following HP C++ (cfront) option is not supported in HP aC++.

    -y
    For HP C++ (cfront), the -y option generates a Static Analysis database if SoftBench is installed and /opt/softbench/bin is at the beginning of your path. The option is not required for HP aC++.

    Obsolete Exception Handling Option

    The following HP C++ (cfront) option is not supported in HP aC++.
    +eh
    To use exception handling with HP C++, you must use this option when compiling all files in your application.

    In HP aC++, exception handling is in effect by default. To turn exception handling off, you must compile with the +noeh option.

    Obsolete Library Option

    The following HP C++ (cfront) library option is not supported in HP aC++.
    -depth
    For HP C++ (cfront), this option is used to instruct the run-time system to traverse the shared library list in a depth-first manner when calling static constructors and when loading the libraries. The default is to traverse the shared libraries in a left-to-right order when calling static constructors. The order of execution of static constructors within each shared library is not affected by this option.

    For HP aC++, -depth funtionality is the default. The option is therefore unnecessary.

    Obsolete Null Pointer Option

    The following HP C++ (cfront) library option is not supported in HP aC++.
    -Z
    Allow dereferencing of null pointers at run time. The value returned from a dereferenced null pointer is zero. This is the default behavior for HP C++ (cfront) and for HP aC++.

    Obsolete Preprocessor Options

    HP aC++ provides support for ANSI/ISO C++ International Standard preprocessing. Since the standard categorizes support of pre-ISO preprocessing as an anachronism, the ANSI preprocessing options of HP C++ (cfront) are not supported.

    -Aa
    Requests the ANSI mode HP C++ preprocessor, cpp.ansi. This is the HP C++ (cfront) default.
    -Ac
    Requests the compatibility mode HP C++ preprocessor, cpp, not available in HP aC++.

    For this release of HP aC++, the following options are not supported.

    -C
    Prevents the preprocessor from stripping comments from your source file; comments are retained.
    -Wp
    The -W option no longer accepts p as a subprocess parameter. In HP aC++, there is no separate subprocess for the preprocessor.

    Use the CC command (HP C++) as a workaround, as in the following example:

    CC prog.C -I /opt/aCC/include -I /opt/aCC/include/iostream -I /usr -I /usr/include 
    

    For More Information

    Obsolete Template Options

    In HP aC++, templates are processed differently than in HP C++ (cfront). New template options provide additional functionality. Refer to Using HP aC++ Templates and Migration Considerations when Using Templates for information.

    The following HP C++ (cfront) template options are not supported in HP aC++.

    -pta
    Instantiates all members of used template classes and all needed template functions.
    -ptb
    Invokes ld instead of nm to do simulated linking.
    -pth
    Uses short file names for template instantiation files.
    -ptH"list"
    Specifies file name extensions for template declaration files (header files).
    -ptn
    Instantiates at link time rather than compile time.
    -ptrpath
    Specifies an alternate location for the template repository.
    -pts
    Splits template instantiations into separate object files.
    -ptS"list"
    Specifies file name extensions for template definition files.

    For HP aC++, use the +inst_include_suffixes option. Note this option must be used with the +inst_implicit_include option.

    -ptv
    Gives verbose information about template processing.

    For HP aC++, use the +inst v option.

    -tx,name
    The following values for x are related to template subprocesses and are not supported in HP aC++.
    • i -- Link-time template processor, c++ptlink
    • r -- Compile-time template processor, c++ptcomp
    -Wx,args
    The following values for x are related to template subprocesses and are not supported in HP aC++.
    • i -- Link-time template processor, c++ptlink
    • r -- Compile-time template processor, c++ptcomp

    Obsolete Translator Mode Options

    HP aC++ is ANSI C conformant and does not support a C++ to C translator mode. The following HP C++ (cfront) translator mode options are not valid in HP aC++.

    +a0
    Causes the translator to produce Classic C style declarations.
    +a1
    Causes the translator to produce ANSI C style declarations.
    -F
    Runs only the preprocessor and translator, sending the resulting source code to standard output (stdout).
    -Fc
    Similar to the -F option, except that C source code is generated.
    +i
    Generates an intermediate C language source file having the file name suffix ..c in the current directory.
    +m
    Provides maximum compatibility with the USL C++ implementation.
    +Rnumber
    Allows only the first number register variables to actually be promoted to the register class.
    +T
    Requests translator mode.
    -tx,name
    The following values for x are related to translator mode and are not supported in HP aC++.
    • 0 (zero) -- C compiler
    • c -- C compiler
    • m -- merge tool, c++merge
    • p -- preprocessor
    • P -- patch tool, c++patch
    -Wx,args
    The following values for x are related to translator mode and are not supported in HP aC++.
    • 0 (zero) -- C compiler
    • c -- C compiler
    • m -- merge tool, c++merge
    • p -- preprocessor
    • P -- patch tool, c++patch
    +xfile
    Reads a file of data types, sizes, and alignments which the compiler uses when generating code.

    Obsolete Virtual Table Options

    The following HP C++ (cfront) virtual table options do not apply in HP aC++.

    +e0
    Causes virtual tables to be external and defined elsewhere, that is, uninitialized.
    +e1
    Causes virtual tables to be declared externally and defined in a given module, that is initialized.

    Obsolete Template and Translator Mode Arguments for -tx,name

    For the -tx,name option, the following arguments for x, related to translator mode and template subprocesses, are not supported in HP aC++.

    Obsolete Template and Translator Mode Arguments for -Wx,args

    For the -Wx,args option, the following arguments for x, related to translator mode and template subprocesses, are not supported in HP aC++.

    Changed Command-Line Options

    Functionality for the following options is different for HP C++ (cfront) than it is for HP aC++.

    -E
    Functionality of the -E option has changed. It now runs the preprocessor only on named C++ files, not on assembly files, and sends the result to standard output (stdout).

    -g
    Functionality of the -g debugger option has changed. It now generates minimal information for the debugger as does the -g1 option. This is the default.

    The -g0 option replaces -g and generates full debug information for the debugger.

    For more information, refer to HP aC++ Debugging Options.

    -tx,name
    The following values for x are related to translator mode and template subprocesses and are not supported in HP aC++.
    • 0 (zero) -- C compiler
    • c -- C compiler
    • i -- Link-time template processor, c++ptlink
    • m -- merge tool, c++merge
    • p -- preprocessor
    • P -- patch tool, c++patch
    • r -- Compile-time template processor, c++ptcomp

    -Wx,args
    The following values for x are related to translator mode and template subprocesses and are not supported in HP aC++.
    • 0 (zero) -- C compiler
    • c -- C compiler
    • i -- Link-time template processor, c++ptlink
    • m -- merge tool, c++merge
    • p -- preprocessor
    • P -- patch tool, c++patch
    • r -- Compile-time template processor, c++ptcomp

    Compiler Coexistence

    The HP C++ and HP aC++ compilers execute independently and can be installed on a single system.

    HP C++ is located at:

       /opt/CC

    HP aC++ is located at:

        /opt/aCC

    Migration Considerations when Debugging

    The HP/DDE Debugger supports HP aC++. The HP Symbolic Debugger, xdb, is not supported.

    Functionality of the -g debugger option has changed. It now generates minimal information for the debugger as does the -g1 option. This is the default.

    The -g0 option replaces -g and generates full debug information for the debugger.

    For more information, refer to HP aC++ Debugging Options.

    HP aC++ Messages

    As you migrate your code from HP C++ to HP aC++, you are likely to see many error and warning messages related to standards based syntax.

    It may be helpful to compile using HP C++ (cfront) with the +p option. Then when the compiler encounters a standards based reserved word that is used as an identifier, it generates a warning message indicating that this syntax will cause an error in HP aC++.

    Interpreting HP aC++ Messages

    The aC++ compiler can issue a large variety of diagnostics in response to unexpected situations or suspicious constructs. These diagnostics can be classified as follows:

    Command Errors
    These are issued when the command line is not correctly formed and the compiler cannot proceed with compilation.
    Command Warnings
    These sometimes occur when an option is not recognized, but compilation proceeds without that option.
    Fatal Errors
    These are issued for ill formed programs for which the compiler cannot recover reliably. Syntax errors usually fall into this category. No object file will be generated if such an error is encountered.
    Future Errors
    These are actually serious warnings indicating that a language rule was violated, but the compiler will continue generating code. These warnings can be turned into hard errors by using the +p option (pedantic mode).
    Anachronisms
    These warnings also diagnose ISO/ANSI C++ language violations. Code that triggers this sort of diagnostic was considered legal in the past.
    Warning
    These help in identifying possible sources of bugs, often because the code triggers behavior that is not precisely defined by the C++ standard.
    Suggestion/Informational
    These diagnostics are not emitted unless the -w option is provided. In that case, the compiler attempts to identify more suspicious constructs.
    Tool Errors
    Very rarely, aC++ may fail in a component that is not specific to the C++ language (e.g., the PA-RISC optimizer); in that case, a Tool Error is emitted. The compilation process cannot recover from these, and they are often a sign of a defect in the compiler.

    Frequently Encountered Messages

    Frequently encountered diagnostic message numbers are listed and described in the HP aC++ Transition Guide at the following URL:

    http://www.hp.com/esy/lang/cpp/tguide/
    


    Migration Considerations when Using Exception Handling

    When migrating exception handling code, be aware of the following characteristics of HP aC++ which differ from those of HP C++ (cfront):

    See Also

    Exception Handling is the Default

    In HP aC++ exception handling is on by default. Use the +noeh option if you need to turn exception handling off. Note that with exception handling disabled, the keywords throw and try generate a compiler error.

    The HP C++ (cfront) compiler, behaves differently; the default is exception handling off. To turn it on, you must use the +eh option which is obsolete in HP aC++.

    CAUTION: If your executable throws no exceptions, object files compiled with and without the +noeh option can be mixed freely.

    However, in an executable which throws exceptions (note that HP aC++ run-time libraries throw exceptions), you must be certain that no exception is thrown in your application which will unwind through a function compiled without the exception handling option turned on. In order to prevent this, the call graph for the program must never have calls from functions compiled without exception handling to functions compiled with exception handling (either direct calls or calls made through a callback mechanism). If such calls do exist, and an exception is thrown, the unwinding can cause:

    Memory Allocation Failure and operator new

    In HP aC++ programs, when either operator new ( ) or operator new [ ] cannot obtain a block of storage, a bad_alloc exception results. This is required by the ANSI/ISO C++ International Standard.

    In HP C++, memory allocation failures return a null pointer (zero) to the caller of operator new ().

    To handle memory allocation failures in HP aC++ and avoid a program abort, do one of the following:

    Possible Differences when Exiting a Signal Handler

    Behavior when exiting a signal handler via a throw (which, according to the ANSI/ISO C++ International Standard remains "undefined"), may differ between the two compilers.

    In HP aC++, a try block begins following the first call after the try keyword. This conforms to the standard which considers that prior to the first call, a legal exception cannot be thrown which would consider the current try block's handlers as candidates to catch the exception.

    In HP C++ the try keyword defines the beginning of a try block.

    Thus, if a signal were taken while executing between the try keyword and the first call's return point, a throw from the signal handler would not find the associated handlers to be candidates for catching the exception.

    Differences in setjmp/longjmp Behavior

    Interoperability with setjmp/longjmp (undefined by the ANSI/ISO C++ International Standard) is unimplemented.

    The standard has the following verbiage, suggesting that an implementation is not obligated to clean up objects whose lifetimes are shortened by a longjmp:

    The function signature longjmp(jmp_buf jbuf, int val) has more restricted behavior in this International Standard. If any automatic objects would be destroyed by a thrown exception transferring control to another (destination) point in the program, then a call to longjmp(jbuf, val) at the throw point that transfers control to the same (destination) point has undefined behavior.

    Calling unexpected

    Unlike HP C++, in HP aC++ an unexpected-handler cannot throw anything it pleases. If it wants to exit via a throw, it must throw an exception that is legal according to the exception specification that caused unexpected() to be called, unless that exception specification includes the predefined type bad_exception. If it does include bad_exception and the type thrown from the unexpected-handler is not in the exception specification, then the thrown object is replaced by a bad_exception object and throw processing continues.

    The following example is legal in HP C++ but not in HP aC++. You can make the example legal by including the exception header and adding bad_exception to foo's throw specification. The catch(...) in main will then catch a bad_exception object. This is the only legal way an unexpected-handler can rethrow the original exception.

    //     #include       Needed to make the example legal.
    
    void my_unexpected_handler() { throw; }
    
    void foo() throw() {
    
    //     void foo() throw(bad_exception) {   To make the example legal,
    //                                         replace the previous line
    //                                         of code with this line.
    
    throw 1000;
    }
    
    int main() {
    set_unexpected( my_unexpected_handler );
    try {
    foo();
    }
    catch(...) {
    printf("fail - not legal in aCC\n");
    }
    return 0;
    }
    

    Following is another example, illegal because my_unexpected_handler is rethrowing an int. A possible conversion is to throw &x instead, since this is a pointer to int and therefore legal with respect to the original throw specification. Alternatively, you could add bad_exception to the throw specification, as in the prior example.

    int x = 1000;
    
    void my_unexpected_handler() { throw; }
    
    void foo() throw( int * ) {
    throw 1000;
    }
    
    int main() {
    set_unexpected( my_unexpected_handler );
    try {
    foo();
    }
    catch(...) {
    printf("fail - not legal in aCC\n");
    }
    return 0;
    }
    

    Unreachable catch Clauses

    Unreachable catch clauses are diagnosed by HP C++ but not by HP aC++. For example:

    class C {
    // ...
    };
    
    class D : public C {
    // ...
    };
    
    ...
    
    catch(C) {
    }
    catch(D) {          // Unreachable since previous catch masks this one.
                        // Throw of D will be caught by catch for base class.
    }
    
    catch(C * ) {
    }
    catch(D * ) {       // Unreachable since previous catch masks this one.
                        // Throw of D * will be caught by catch for pointer
                        // to base class.)
    }
    

    Throwing an Object having an Ambiguous Base Class

    HP C++ generates an error for the throw of an object having an ambiguous base class. In HP aC++, a throw of an object having an ambiguous base class is not caught by a handler for that base, since that would involve a prohibited derived->base conversion.

    In the following example, the throws are caught by the handlers for D1 and D1*, respectively. The handlers for C are disqualified because C is an ambiguous base class of E:

    extern "C" int printf(char*,...);
    
    class C {
    public:
    C() {};
    };
    
    class D1 : public C {
    public:
    D1() {};
    };
    
    class D2 : public C {
    public:
    D2() {};
    };
    
    class E: public D1, public D2 {
    public:
    E() {};
    };
    
    int main() {
    E e;
    try {
    throw e;
    }
    catch(C) {
    printf("caught a C object\n");
    }
    catch(D1) {
    printf("caught a D1 object\n");
    }
    catch(D2) {
    printf("caught a D2 object\n");
    }
    catch(E) {
    printf("caught an E object\n");
    }
    
    try {
    throw & e;
    }
    catch(C*) {
    printf("caught ptr to C object\n");
    }
    catch(D1*) {
    printf("caught ptr to D1 object\n");
    }
    catch(D2*) {
    printf("caught ptr to D2 object\n");
    }
    catch(E*) {
    printf("caught ptr to E object\n");
    }
    return 0;
    }
    

    Migration Considerations when Using Libraries

    Choose from the following sections for information about library migration from HP C++ (cfront) to HP aC++. Note that the Complex Library and the Task Library are no longer supported. For information about availability of the HP Codelibs Library, contact your HP support representative.

    Standards Based Libraries

    HP aC++ provides the following libraries that are not part of the HP C++ (cfront) compiler: It is highly recommended that you use these standards based libraries whenever possible, instead of the cfront compatibility libraries.

    HP C++ (cfront) Compatibility Libraries

    HP aC++ provides the following libraries whose functionality is part of the HP C++ (cfront) compiler. These libraries are not standards based.

    HP aC++ A.01.21 Run-time Support Library

    The following HP aC++ libraries replace the cfront based HP C++ libraries:

    Since the K & R float to double promotion rule is not supported, no equivalents to libC and libC.ansi are available.

    For More Information

    For your reference, the files containing the HP C++ (cfront) run-time libraries are listed below. Different libraries are used depending on whether or not you use exception handling.

    HP C++ 3.x Stream Library File Locations (default version, without exception handling)

    HP C++ 10.x Stream Library File Locations (default version, without exception handling)

    HP C++ (cfront) Stream Library File Locations (exception handling version)

    IOStream Library

    The shared version of this library is located at /usr/lib/libstream.sl. The archive version is at /usr/lib/libstream.a.

    Manual Pages

    Header Files

    The following header files are for use with the IOStream library. To direct the compiler to search these header files, use -I/opt/aCC/include/iostream.

    Standard Components Library

    The Standard Components Library is provided for compatibility with the cfront based HP C++ compiler. In place of the Standard Components Library, it is highly recommended that you use the similar features of the Standard C++ Library.

    When using the Standard Components Library, note the following:

    Manual Pages

    Manual pages are located at /opt/aCC/share/man/man3.Z. To invoke a man page from the command line, enter 3s after the man command and before the man page name. For example, to invoke the man page for Args:
    man 3s Args
    

    Header Files

    Standard Components header files and template source files are listed below. To direct the compiler to search these header files, specify -I/opt/aCC/include/SC.

    Migration Considerations

    HP C++ 3.x Standard Components Library File Locations

    Default version:

    Exception handling version:

    HP C++ 10.x Standard Components Library File Locations

    Default version:

    Exception handling version:

    HP C++ (cfront) Complex Library Not Supported

    The Complex library which is part of the cfront based HP C++ compiler product is not included with HP aC++. In place of the Complex library, it is recommended that you use the similar features of the Standard C++ Library.

    To begin your migration:

    Manual Pages Not Available

    The following manual pages describing the complex library are not part of the HP aC++ product:

    Header File Not Available

    The Complex library uses the complex.h header file.

    HP C++ (cfront) Task Library Not Supported

    The task library which is part of the HP C++ compiler product is not included with HP aC++. To develop multi-threaded applications with HP aC++, use the pthread programming interface routines that are available as part of HP DCE/9000.

    Manual Pages Not Available

    The following manual pages describing task library features are not part of the HP aC++ product:

    Migration Considerations Related to Performance and File Size

    For information about HP aC++ performance and file size considerations, refer to the following:

    Migration Considerations Related to Preprocessing

    The HP C++ (cfront) compiler provides ANSI mode (the default) and K & R compatibility mode preprocessing.

    HP aC++ preprocessing complies with the ANSI/ISO C++ International Standard. Therefore, if you are migrating from cfront ANSI mode preprocessing to HP aC++, in general, no changes are required.

    HP aC++ does not support K & R compatibility mode preprocessing.

    For More Information


    Migration Considerations Related to Standardization

    The ANSI/ISO C++ International Standard redefines the C++ language in terms of rules, syntax, and features.

    If your existing code contains any of the standards based keywords as variable names, you must change the variable names when you convert your program to an HP aC++ program.

    In addition to keyword changes, there are changes in C++ Semantics and C++ Syntax.

    See Also:

    Migration - C++ Semantics

    When you migrate from HP C++ to HP aC++, your code will behave differently in the following areas, even though it may compile without errors or warnings.

    Implicit Typing of Character String Literals

    HP C++ implicitly types character string literals as char *. HP aC++ in accordance with the ANSI/ISO C++ International Standard, types character string literals as const char *.

    This difference affects function overloading resolution. For example, in the following code, HP aC++ calls the first function a; cfront calls the second.

    void a(const char *);
    void a(char *);
    
    f() {
        a("A_STRING");
        }
    

    To prevent existing code like the following from breaking, the ANSI/ISO C++ International Standard does make a provision to allow the assignment of a string literal to a non-const pointer.

    char *p = "B_STRING";
    

    NOTE: The ANSI/ISO C++ International Standard defines the above as a deprecated feature, that is, not guaranteed to be part of the Standard in future revisions.

    Also, in a conditional expression like the following, the conversion of const char * to char * is not provided for in this context.

    char *p = f() ? "A" : "B";
    

    The code could be changed in several ways, for example:

    const char *p = f() ? "A" : "B";
    
    or
    char *p = const_cast(f() ? "A" : "B");
    

    Overload Resolution Ambiguity of Subscripting Operator

    HP C++ and HP aC++ have different overload resolution models. When migrating to HP aC++, you may see an overload resolution ambiguity for the subscripting operator. The following code illustrates the problem:

    struct String {
       char& operator[](unsigned);
       operator char*();
    // ...
    };
    
    void f(String &s) {
       s[0] = '0';
    }
    

    HP C++ accepts the above code, selecting String::operator[](unsigned) rather than the user-defined conversion, String::operator char*(), followed by the built-in operator[].

    Compiling the above with HP aC++ produces an error like the following:

       Error 225: "c.C", line 8 # Ambiguous overloaded function call;
           more than one acceptable function found. Two such functions
           that matched were "char &String::operator [](unsigned int)"
           ["c.C", line 2] and "char &operator [](char *,int)" 
           [Built-in operator].
                   s[0] = '0';
                   
    

    The error message is issued (correctly) because the compiler cannot choose between:

    1. not converting `s', but converting `0' from type int to type unsigned int; this implies using the user- provided subscript operator[]

    2. converting `s' to type char* (using the user-defined conversion operator), but not converting `0'; this corresponds to using the built-in subscript operator[].

      In order to disambiguate this situation in favor of the user-provided subscript operator[], make the conversion of `0' in alternative 1. no worse than the conversion of `0' in alternative 2. Because the subscript type for the built-in operator[] is ptrdiff_t (as defined in <stddef.h>), this is also the type that should be used for user-defined subscript operators. The example above should therefore be replaced by:

      #include 
      
      struct String {
         char& operator[](ptrdiff_t);
         operator char*();
         // ...
      };
      
      void f(String &s) {
         s[0] = '0';
      }
      

      Note that "worse" is relative to a ranking of conversions as described in the ANSI/ISO C++ International Standard on overloading. In general, a user-defined conversion is worse than a standard conversion, which in turn is worse than no conversion at all. The complete rules are more fine- grained.

      Execution Order of Static Constructors in Shared Libraries

      In HP C++ (cfront), static constructors in shared libraries listed on the link-line are executed, by default, in left-to-right order. HP aC++ executes static constructors in depth-first order; that is, shared libraries on which other files depend are initialized first. Use the -depth command-line option on the CC command line for the greatest compatibility with HP aC++.

      In addition, HP aC++ reverses the initialization order of .o files on the link-line. To aid in migration, you can group all .o files together and all .sl files together, as in the following example:

      aCC file1.o file2.o lib1.sl lib2.sl lib3.sl
      
      Given the above link-line, cfront would initialize file2.o and than file1.o, while HP aC++ initializes file1.o and than file2.o. You should take this into account in your cfront code to avoid link problems with HP aC++.

      More Frequent Inlining of Inline Code

      HP C++ does not actually inline some functions even though you have requested inlining. This happens when the function is too complex. If you use the +w option, the compiler displays a message whenever it does not inline a function you wanted inlined.

      HP aC++ almost always inlines functions for which you have specified the inline keyword.

      Migration - C++ Syntax

      When you migrate from HP C++ to HP aC++, in addition to changes related to standards based keywords, you may need to make changes to your source code in the following areas:

      Migration - Explicit int Declaration

      HP C++

      You do not need to explicitly specify int types.

      HP aC++

      You must explicitly declare int types. This change reduces opportunities for ambiguity between expressions involving function-like casts and declarations.

      Change Needed

      Explicitly declare int types.

      Example

      The following code is valid in HP C++:
      void f(const parm); 
      const n = 3; 
      main() 
      
      The equivalent, valid HP aC++ code follows:
      void f(const int parm); 
      const int n = 3; 
      int main() 
      

      Migration - for Statement, New Scoping Rules

      HP C++

      Variables declared in the initializer list are allowed after the for statement.

      HP aC++

      In the ANSI/ISO C++ International Standard, variables declared in the initializer list are not allowed after the for statement. HP aC++ provides this functionality when you specify the following aCC command-line option:
      -WC,-ansi_for_scope,on
      
      If you do not specify this option, (or you specify the option -WC,-ansi_for_scope,off) by default the new rules do not take effect.

      Change Needed

      At this time, HP aC++ provides this standard functionality as an option to ease conversion of existing code to the standard. No code change is currently required.

      Future plans are to make the ANSI/ISO C++ International Standard syntax the default. Therefore, it is recommended that you correct your code, by moving the declaration of the for loop variable to its enclosing block.

      Example

      The following code currently compiles error free with HP C++ and HP aC++. In the future, HP aC++, will generate an error.

      int main(int argc) {
      	for (int i = 1; i < argc; ++i) {
              }
              for (i = 0; i < argc; ++i) {
              }
      }
      
      Correct the code as follows:

      int main(int argc) {
      	int i;
              for (i = 1; i < argc; ++i) {
              }
              for (i = 0; i < argc; ++i) {
              }
      }
      
      Corrected code complies with ANSI/ISO C++ International Standard syntax and compiles with either compiler.

      Migration - struct as Template Type Parameter is Permitted

      HP C++

      An error is generated when a struct is used as a template type parameter.

      HP aC++

      When a struct is used as a template type parameter, it is correctly compiled, in accordance with draft standard syntax.

      Change Needed

      This is a new feature.

      Example

      template  class A {
      public:
      struct T a;
      };
      struct B {};
      A b;
      
      Compiling the above code with HP C++ causes an error like the following:
      CC: "DDB4325.C", line 3: error:  T of type any  redeclared as struct (1479)
      
      The code compiles without error with HP aC++

      Migration - Base Template Class Reference Syntax Change

      HP C++

      You can reference a member of a base template class without qualifying the member.

      HP aC++

      When referencing a member of a base template class, you should qualify the member by adding a this->.

      Change Needed

      Adding this-> forces name resolution to be deferred until instantiation which allows the compiler to find members in template base classes. This rule prevents the compiler from finding names declared in enclosing scopes when that is unintended.

      Example

      template  class BaseT {
      public:
        T t;
        int i;
      };
      template  class DerivedT : public BaseT {
      public:
        void foo1 () { t = 1; i = 1; }               //  warning 721
                                                     //  t and i could be global.
      
        void foo2 () { this->t = 2; this->i = 2; }   //  Correct syntax, no warning.
      };
      DerivedT d;             // Here is the point of instantiation.
      

      Migration - Tokens after #endif

      HP C++ Behavior

      Any characters following the #endif preprocessor statement cause a warning and are ignored.

      HP aC++ Behavior

      Any characters following the #endif preprocessor statement cause an error and the program does not compile.

      Change Needed

      Remove all characters following all #endif preprocessor statements or put the token in comments.

      Example

      Compiling the following code with HP C++ causes a warning. Compiling with HP aC++ generates an error.

      int main(){
      #ifdef FLAG
      int i;
      i=1;
      #endif FLAG
      }
      

      To compile with HP aC++, you can change the code to the following:

      int main(){
      #ifdef FLAG
      int i;
      i=1;
      #endif //FLAG
      }
      

      Migration - overload not a Keyword

      HP C++

      Using the overload keyword to specify that a function is an overloaded function causes an anachronistic warning and is ignored.

      HP aC++

      Using the overload keyword causes an error and the program does not compile.

      Change Needed

      Remove all uses of the overload keyword.

      Example

      Compiling the following code with HP C++ causes a warning. Compiling with HP aC++ generates an error stating that overload is used as a type, but has not been defined as a type.
      int f(int i);
      overload int f(float f);   // Remove the word overload.
      int main () {
      return 1;
      }
      

      Migration - Dangling Comma in enum

      HP C++

      A comma following the last element in an enum list is ignored.

      HP aC++

      A comma following the last element in an enum list generates an error.

      Change Needed

      Remove the comma after the last element.

      Example

      HP C++ accepts the following code. HP aC++ generates an error stating that the , is unexpected.
      enum Colors { red,
                    orange,
                    yellow,
                    green,
                    blue,
                    indigo,
                    violet,     // This comma is illegal.
      };
      

      Migration - Static Member Definition Required

      HP C++

      Declaring a static member but not defining it is allowed.

      HP aC++

      Declaring a static member but not defining it is not allowed.

      Change Needed

      Add a definition of the static data member.

      Example

      Compiling and linking the following code on HP C++ gives no warning nor error.

      Compiling the code on HP aC++ gives no warning nor error. Linking the resulting object file generates a linker (ld) error stating that there are unsatisfied symbols.

      class A {
      public:
         static int staticmember;
      };
      // int A::staticmember=0;   // This would fix the problem.
      int main ()
      {
         A::staticmember=1;
      }
      

      Migration - Declaring friend Classes

      HP C++

      Declaring friend classes without the class keyword is allowed.

      HP aC++

      Declaring friend classes without the class keyword generates an error.

      Change Needed

      Add the class keyword to all friend class declarations.

      Example

      Compiling the following code on HP C++ gives no warning nor error. Compiling the code on HP aC++ generates an error stating that the friend declaration for B is not in the right form for either a function or a class.
      class foo{
      
      public:
         friend bar;     // Need to say:  friend class B
      };
      int main (){
         return 1;
      }
      

      Migration - Incorrect Syntax for Calls to operator new

      HP C++

      Incorrect syntax for the use of a value to a call to operator new is allowed.

      HP aC++

      An error is generated when this incorrect syntax for opertor new is used.

      Change Needed

      Add parentheses around the use of operator new. This code compiles correctly with both HP C++ and HP aC++.

      Example

      Compiling the following code on HP C++ gives no warning nor error. Compiling the code on HP aC++ generates errors stating operator expected instead of new and Undeclared variable operator S.
      struct S {int f();};
      int g() { return new S->f();}
      // int g() { return (new S)->f();}    // This would fix the problem. 
      int S:: f( ) { return 1;}
      main() {
      return 1; }
      

      Migration - Using :: in Class Definitions

      HP C++

      Members of classes are incorrectly allowed to be declared inside the class using the syntax:
      class_name::member_name
      

      HP aC++

      This incorrect syntax is considered an error.

      Change Needed

      Remove the class_name:: specification from the member definition.

      Example

      Compiling the following code on HP C++ gives no warning nor error. Compiling the code on HP aC++ generates an error stating that you cannot qualify members of Class X in the class definition.
      class X{
         int X::f();
      // int f();     // This would fix the problem and 
                      // run successfully on both compilers. 
      >
      int main(){
      }
      

      Migration - Duplicate Formal Argument Names

      HP C++

      Duplicate formal argument names are allowed.

      HP aC++

      Duplicate formal argument names generate an error.

      Change Needed

      Use unique formal parameter names.

      Example

      The following code compiles with HP C++. With HP aC++, an error is generated stating that symbol aParameter has been redefined and where it was previously defined.
      int a(int aParameter, int * aParameter); 
      

      Migration - Ambiguous Function/Object Declaration

      HP C++

      An ambiguous function/object declaration compiles without warning, assuming an object declaration.

      HP aC++

      An ambiguous function/object declaration generates an error.

      Change Needed

      Change the code to remove the ambiguity.

      Example

      struct A {A(int);};
      struct B {B(const A &); void g();};
      void f(int p) {
         B b(A(p));   // Declaration of function or object?
         b.g();       // Error?
      } 
      
      The ambiguity in the above code is whether b is being declared as:
      • a function with one argument (named p) returning an object of type B.
      • an object of type B initialized with a temporary object of type A.

      HP C++ compiles this code successfully and assumes b is an object. Compiling the code with HP aC++ causes an error like the following:

      Error: File "objDeclaration.c", Line 5
      Left side of '.' requires a class object; type found was a function 'B (A)'.
           Did you try to declare an object with a nested constructor call?
           Such a declaration is interpreted as a function declaration B b(A)
           [File "objDeclaration.c, Line 4].
      

      Modify the code as shown below for successful compilation with both compilers.

      struct A {A(int);};
      struct B {B(const A &); void g();};
      
      void f(int p) {
         B b = A(p);    // declaration of object
         b.g();         // method call
      }
      

      Migration - Overloaded Operations ++ and --

      Overloaded operations ++ and -- must be correctly used. These operations require a member function with one argument. If the function has no argument:

      HP C++

      A warning is issued and a postfix operation is assumed.

      HP aC++

      The inconsistency between the overloaded function usage and definition is considered an error.

      Change Needed

      Change the class definition so that each overloaded function definition has the correct number of arguments.

      Example

      class T {
         public:
            T();
            const T& operator++ ();
      };
      int main () {
      T t;
      t++;
      }
      

      Compiling the above code with HP C++ causes a warning like the following:

      CC: "pre.C", Line 8: warning: prefix ++/-- used as postfix (anachronism) (935)
      

      Compiling the code with HP aC++ generates an error like the following:

      Error 184: File "pre.C", Line 8
      Arithmetic or pointer type expected for operator '++'; type found was 'T'.
      

      To compile the code with either HP C++ or HP aC++ use the following class definition:

      class T {
         public:
            T();
            const T& operator++ ();     // prefix    old style postfix definition
            const T& operator++ (int);  // postfix
      };
      

      Migration - Reference Initialization

      Illegal reference initialization is no longer allowed.

      HP C++

      A warning is generated stating that the initializer for a non-constant reference is not an lvalue (anachronism).

      HP aC++

      An illegal initialization of a reference type causes an error and the program does not compile.

      Change Needed

      Use a constant reference.

      Example

      void f() {
         char c = 1;
         int & r = c;
      }
      
      Compiling the above code with HP C++ causes a warning like the following:
      C: "nonConstRef.C", line 6: warning: initializer for non-const
      reference not an lvalue (anachronism)( (235)
      

      Compiling the code with HP aC++ generates an error like the following:

      Error: File "nonConstRef.C", Line 6
      Type mismatch; cannot initialize a 'int &' with a 'char'.
      Try changing 'int &' to 'const int &'.
      

      For successful compilation with both compilers, change the code as shown below:

      void f() {
          char c = 1;
          const int & r = c;
      }
      

      Migration - Using operator new to Allocate Arrays

      HP C++

      operator new is called to allocate memory for an array.

      HP aC++

      operator new [] is called to allocate memory for an array.

      Change Needed

      Change operator new to operator new [ ].

      Example

      typedef char CHAR;
      typedef unsigned int size_t;
      typedef const CHAR *LPCSTR, *PCSTR;
      typedef unsigned char BYTE;
      
      void* operator new (size_t nSize, LPCSTR lpszFileName, int nLine);
      static char THIS_FILE[] = "mw2.C";
      int main() {
         BYTE *p;
         p = new(THIS_FILE, 498) BYTE[50];
      }
      
      The above code compiles without error on HP C++. On HP aC++, an error like the following is generated:
      Error: File "DDB4269.C", Line 10
      Expected 1 argument(s) for void *operator new [ ](unsigned int); had 3 instead.
      

      For More Information

      Migration - Parentheses in Static Member Initialization List

      HP C++

      Redundant parentheses are allowed in a static member initialization list.

      HP aC++

      Redundant parentheses in a static member initialization list cause an error and the program does not compile.

      Change Needed

      Remove the redundant parentheses. The resulting code compiles correctly with either HP C++ or HP aC++.

      Example

      class A {
      public:
         int i;
         static int (A::*p);
      };
      
      int (A::*(A::p)) = &(A::i);
      
      Compiling the above code with HP aC++ causes an error like the following:
      Error: File "DDB4270.C", Line 7
      A pointer to member cannot be created from a parenthesized or unqualified name.
      
      To successfully compile the code, remove the parentheses form the last line, as in the following example:
      class A {
      public:
         int i;
         static int (A::*p);
      };
      
      int (A::*(A::p)) = &A::i;
      

      Migration - &qualified-id Required in Static Member Initialization List

      HP C++

      An unqualified function name in a static member initialization list is allowed.

      HP aC++

      An unqualified function name in a static member initialization list causes an error and the program does not compile.

      Change Needed

      Use the unary operator & followed by a qualified-id in the member initialization list. The resulting code compiles correctly with either HP C++ or HP aC++.

      Example

      class A {
      public:
         int i;
         int j();
      static int (A::*p)();
      };
      int (A::*(A::p))() = j;
      
      Compiling the above code with HP aC++ causes the following error:
      Error: File "DDB4270A.C", Line 7
      Cannot initialize 'int (A::*)()' with 'int (*)()'.
      
      To successfully compile with either HP C++ and HP aC++, change the initialization list in line 7 to &A::j;
      class A {
      public:
         int i;
         int j();
      static int (A::*p)();
      };
      int (A::*(A::p))() = &A::j;
      

      Migration - Non-constant Reference Initialization

      HP C++

      If you do not initialize a non-constant reference with an lvalue, an anachronistic warning is issued and compilation continues.

      HP aC++

      An error is issued if you do not use an lvalue for a non-constant reference initialization.

      Change Needed

      Use an lvalue for the reference initialization, or define the reference as a const type.

      Example

      void f(int &);
      int main () {
         f(3);
         return 0;
      }
      
      Compiling the above code with HP C++ generates a warning like the following:
      CC: "DDB04313A.C", line 4: warning: temporary used for non-const int & argument;
       no changes will be propagated to actual argument (anachronism) (283)
      
      Compiling the above code with HP aC++ generates an error like the following:
      Future Error: File "DDB04313A.C", Line 4
      The initializer for a non-constant reference must be an lvalue.
      	Try changing 'int &' to 'const int &'.
      
      To successfully compile the code with either compiler, use one of the two alternatives shown below:
      void f(const int &);  // Use a constant reference.
      int main () {
         f(3);
         return 0;
      }
      
      void f(int &);
      int i;
      int main () {
         i=3;
         f(i);              // Use an lvalue for reference initialization.
         return 0;
      }
      

      Migration - Digraph White Space Separators

      HP C++

      Alternative tokens (digraphs) are not supported.

      HP aC++

      Digraphs are supported and legal C++ syntax can be considered an error because of digraph substitution.

      Change Needed

      Insert a blank between the two characters of the digraph.

      Example

      C<::A> a;
      
      The characters <: are one of the alternative tokens (digraphs) for which HP aC++ performs a substitution. In this case, <: becomes [. The statement to be compiled becomes C[:A a;, which produces many compilation errors.

      To successfully compile this program with either compiler, insert a blank between < and :, as follows:

      C< ::A> a;
      

      Migration Considerations when Using Templates

      In HP aC++, templates are processed differently than in HP C++ (cfront). There is no repository; instead, instantiations are placed in an object (.o) file (with additional information in a .I file if you specify the +inst_auto command-line option). You cannot modify these files as was possible with the files in a repository. Template command-line options are completely different. For information about HP aC++ templates, refer to Using Templates.

      To begin migrating code containing templates to HP aC++, try to compile and link using compile-time instantiation (the default). If this fails with compilation errors, you can compile using one of the following:

      • the +inst_all option to see all compile-time errors, including template instantiation errors. Note, this may generate errors that won't occur in your program, because the draft standard allows template parameters that can't instantiate all members. +inst_all forces instantiation of such members.

      • the +inst_none option to mask compile-time template instantiation errors.

      To reset after all translation units compile successfully:

      • Remove any .o and .I files. Using a clobber makefile target to remove .I files is similar to removing the ptrepository directory in cfront.

      • Recompile and link using compile-time instantiation.

      Verbose Template Processing Information

      Use the +inst v option to replace the cfront -ptv option for verbose template processing information.

      For More Information

      Common Template Migration Syntax Changes

      Template code in HP aC++ needs to use the new keyword typname to distinguish types. Also, data members may need to be referenced using the this-> notation.

      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.

      With the HP C++ (cfront) compiler, for any .h file containing template declarations, there is a .c file containing 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 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 are using 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, as in the following example.

      Note that explicit instantiation can be used to instantiate a template class and all of its member functions, an individual template function, or a template class's member function.

      #!/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*.$$
      

      Migration - Translator Mode is not Supported

      HP aC++ does not support a C++ to C translator mode. For a list of cfront translator mode options that are obsolete, refer to Obsolete Translator Mode Options.