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++.
|
General Migration Guidelines and Tips |
CC +p cfrontfile.C
#if __cplusplus >= 199707L // HP aC++ code #else // HP C++ code #endif // __cplusplus >= 199707L
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 |
aCC
command instead of the CC command used to invoke HP C++.
The following sections describe differences in command-line options:
-g0
For more information, refer to HP aC++ Debugging Options.
+help
+noeh
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++.
Reduce compilation time and executable file size by precompiling common include (header) files.
Select from an Alphabetical List of Obsolete Options or a category of options:
+a1
-Aa
-Ac
-C
-depth
+e0
+e1
+eh
-F
+i
+m
-pta
-ptb
-pth
-ptH"list"
-ptn
-ptr"path"
-ptS"list"
-ptv
+Rnumber
-txname
+T
-Wx,args
-y
-Z
-y
-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++.
+eh
In HP aC++, exception handling is in effect by default. To turn exception handling off, you must compile with the +noeh option.
-depth
For HP aC++, -depth funtionality is the default. The option is therefore unnecessary.
-Z
-Aa
-Ac
For this release of HP aC++, the following options are not supported.
-C
-Wp
-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
The following HP C++ (cfront) template options are not supported in HP aC++.
-pta
-ptb
-pth
-ptH"list"
-ptn
-ptrpath
-pts
-ptS"list"
For HP aC++, use the +inst_include_suffixes option. Note this option must be used with the +inst_implicit_include option.
-ptv
For HP aC++, use the +inst v option.
-tx,name
i -- Link-time template processor, c++ptlink
r -- Compile-time template processor, c++ptcomp
-Wx,args
i -- Link-time template processor, c++ptlink
r -- Compile-time template processor, c++ptcomp
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
Classic C style declarations.
+a1
-F
-Fc
+i
+m
+Rnumber
+T
-tx,name
0 (zero) -- C compiler
c -- C compiler
m -- merge tool, c++merge
p -- preprocessor
P -- patch tool, c++patch
-Wx,args
0 (zero) -- C compiler
c -- C compiler
m -- merge tool, c++merge
p -- preprocessor
P -- patch tool, c++patch
+xfile
+e0
+e1
-tx,name option,
the following arguments for x, related to
translator mode and template subprocesses, 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 option,
the following arguments for x, related to
translator mode and template subprocesses, 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
stdout).
The -g0 option replaces -g and generates full debug information for the debugger.
For more information, refer to HP aC++ Debugging Options.
-tx,name
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
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 |
HP C++ is located at:
/opt/CC
HP aC++ is located at:
/opt/aCC
Migration Considerations when Debugging |
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 |
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++.
Tool Error is emitted. The compilation process cannot recover
from these, and they are often a sign of a defect in the compiler.
http://www.hp.com/esy/lang/cpp/tguide/
Migration Considerations when Using Exception Handling |
new
setjmp/longjmp Behavior
unexpected
catch Clauses
+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:
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:
For example:
operator new (size_t size, const nothrow_t &) throw();
operator new [] (size_t size, const nothrow_t &) throw();
.
.
.
#include
#include
class X{};
void foo1() {
X* xp1 = new(nothrow())X; // returns 0 when creating a nothrow
// object, if space is not allocated
}
void foo2() {
X* xp2 = newX: // may throw bad_alloc
}
void main() {
try {
foo1();
foo2();
}
catch (bad_alloc) {
// code to handle bad_alloc
}
catch(...) {
// code to handle all other exceptions
}
}
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.
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.
unexpectedbad_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 <exception> 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;
}
catch Clauses
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.)
}
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 |
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.
/opt/aCC/lib/libC.a
/opt/aCC/lib/libC.sl
/opt/aCC/lib/libC.ansi.a
/opt/aCC/lib/libC.ansi.sl
/usr/lib/libC.a
/usr/lib/libC.sl
/usr/lib/libC.ansi.a
/usr/lib/libC.ansi.sl
/opt/aCC/lib/aCC/eh/libC.a
/opt/aCC/lib/aCC/eh/libC.ansi.a
The shared version of this library is located at /usr/lib/libstream.sl. The archive version is at /usr/lib/libstream.a.
IOS.INTRO(3C++) -- introduction to the C++ stream library
filebuf(3C++)--buffer for file input and output
fstream(3C++)--iostream and streambuf specialized to
files
ios(3C++)--input/output formatting
istream(3C++)--formatted and unformatted
input
manip(3C++)--iostream manipulators
ostream(3C++)--insertion (storing) into a streambuf
sbuf.prot(3C++)--interface for derived classes
sbuf.pub(3C++)--public interface of character buffering class
ssbuf(3C++)--streambuf specialized to arrays
stdiobuf(3C++)--iostream specialized to stdio FILE
strstream(3C++)--iostream specialized to arrays
-I/opt/aCC/include/iostream.
ios, istream, ostream, and streambuf
Streambuf specialized to arrays
streams and streambufs for
interaction with stdio
iostream.h, fstream.h, stdiostream.h and
iomanip.h for compatibility with AT&T USL C++ version 1.2
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:
HP aC++ has just one set of Standard Components library files located at:
/opt/aCC/lib/lib++.a
/opt/aCC/lib/libGA.a
/opt/aCC/lib/libGraph.a
man 3s Args
SC_intro(3C++) -- introduction to Standard Components
Args(3C++) -- command-line arguments
Array_alg(3C++) -- operations on arrays
Bits(3C++) -- variable-length bit strings
Block(3C++) -- parameterized variable-size arrays
Fsm(3C++) -- simple deterministic finite state machines
Graph(3C++) -- entities and relationships
Graph_alg(3C++) -- operations on graphs
List(3C++) -- parameterized variable-length sequences
Map(3C++) -- parameterized variable-size associative arrays
Objection(3C++) -- rudimentary error-handling
Path(3C++) -- path names and search paths
Pool(3C++) -- special-purpose memory allocators
Regex(3C++) -- regular expressions
Set(3C++) -- parameterized unordered collections
Stopwatch(3C++) -- program execution time measurement
String(3C++) -- variable-length character strings
Strstream(3C++) -- iostream specialized
for String(3C++)
Symbol(3C++) -- unique identifiers based on
character strings
Time_intro(3C++) and Time(3C++) -- absolute
time, time zone and duration
-I/opt/aCC/include/SC.
Default version:
/usr/lib/lib++.a
/usr/lib/libfs.a
/usr/lib/libGA.a
/usr/lib/libGraph.a
/usr/lib/libg2++.a
/usr/lib/incl2
/usr/lib/hier2
/usr/lib/publik2
Exception handling version:
/usr/lib/aCC/eh/lib++.a
/usr/lib/aCC/eh/libfs.a
/usr/lib/aCC/eh/libGA.a
/usr/lib/aCC/eh/libGraph.a
/usr/lib/aCC/eh/libg2++.a
Default version:
/opt/CC/lib/lib++.a
/opt/CC/lib/libfs.a
/opt/CC/lib/libGA.a
/opt/CC/lib/libGraph.a
/opt/CC/lib/libg2++.a
/opt/CC/lib/incl2
/opt/CC/lib/hier2
/opt/CC/lib/publik2
Exception handling version:
/opt/CC/lib/eh/lib++.a
/opt/CC/lib/eh/libfs.a
/opt/CC/lib/eh/libGA.a
/opt/CC/lib/eh/libGraph.a
/opt/CC/lib/eh/libg2++.a
To begin your migration:
The following manual pages describing the complex library are not part of the HP aC++ product:
CPLX.INTRO(3C++) -- introduction to the C++ complex
mathematics library
cartpol(3C++) -- cartesian and polar functions
cplxexp(3C++) -- exponential, logarithm, power, and
square root functions for complex numbers
cplxerr(3C++) -- error handling function
cplxops(3C++) -- complex number operators
cplxtrig(3C++) -- trigonometric and hyperbolic functions
for complex numbers
pthread
programming interface routines that are available as part of HP DCE/9000.
TASK.INTRO(3C++) -- introduction to the C++ task library
interrupt(3C++) -- signal handling
queue(3C++) -- queue routines for message passing and
data buffering
task(3C++) -- the C++ task library
tasksim(3C++) -- histograms and random numbers for
simulations with C++ tasks
Migration Considerations Related to Performance and File Size |
Migration Considerations Related to 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.
Migration Considerations Related to Standardization |
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.
new fails, it throws an execption.
Implicit Typing of Character String Literals |
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:
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:
#includestruct 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.slGiven 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 aC++ almost always inlines functions for which you have specified the
inline keyword.
int Declaration
for Statement - New Scoping Rules
struct as Template Type Parameter is Permitted
typename in Template Declarations
#endif
overload not a Keyword
enum
friend Classes
++ and --
operator new to Allocate Arrays
Migration - Explicit
|
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.
for statement. HP aC++ provides this functionality when you
specify the following aCC command-line option:
-WC,-ansi_for_scope,onIf 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.
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.
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 is used as a template type parameter.
struct is used as a template type parameter, it is
correctly compiled, in accordance with draft standard syntax.
templateCompiling the above code with HP C++ causes an error like the following:class A { public: struct T a; }; struct B {}; A b;
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 |
this->.
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.
templateclass 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
|
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 keyword to specify that a function is an
overloaded function causes an
anachronistic warning and is ignored.
overload keyword causes an error and the program does not compile.
overload keyword.
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
|
, is unexpected.
enum Colors { red,
orange,
yellow,
green,
blue,
indigo,
violet, // This comma is illegal.
};
Migration - Static Member Definition Required |
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 without the class keyword is allowed.
friend classes without the class keyword generates an error.
class keyword to all friend class declarations.
class foo{
public:
friend bar; // Need to say: friend class B
};
int main (){
return 1;
}
Migration - Incorrect Syntax for Calls to operator new |
new.
This code compiles correctly with both HP C++ and HP aC++.
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 |
class_name::member_name
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 |
aParameter has been redefined and where it was previously defined.
int a(int aParameter, int * aParameter);
Migration - Ambiguous Function/Object Declaration | |
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:
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 -- must be correctly used.
These operations require a member function with one
argument. If the function has no argument:
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 |
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 is called to allocate memory for an array.
operator new [] is called to allocate memory for an array.
operator new to operator new [ ].
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.
Migration - Parentheses in Static Member Initialization List |
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 |
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 |
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 |
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 |
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:
To reset after all translation units compile successfully:
+inst v
option to replace the cfront -ptv option for verbose template
processing information.
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 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
+inst include_suffixes
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 |