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()

The for Statement, New Scoping Rules

In HP C++, variables declared in the initializer list are allowed after the for statement. 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 -WC,-ansi_for_scope,offoption), by default, the new rules do not take effect.

In this scenario, 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. HP recommends that you correct your code, by moving the declaration of the for loop variable to its enclosing block.

Example:

The following code currently compiles without errors 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) {

}

}

This code complies with ANSI/ISO C++ International Standard syntax and compiles with both compilers.

struct as Template Type Parameter is Permitted

In HP C++, an error is generated when a struct is used as a template type parameter. In HP aC++, when a struct is used as a template type parameter, it is correctly compiled, in accordance with draft standard syntax. This is a new feature.

Example:

template class A { public:

struct T a; };

struct B {}; A b;

The following error appears when you compile this code with HP C++:

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

Page 212
Image 212
HP C/aC++ for PA-RISC Software manual For Statement, New Scoping Rules, Struct as Template Type Parameter is Permitted