C/C++ Programmer's Guide (G06.27+, H06.03+)

Table Of Contents
MIGRATION_CHECK Messages
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
F-26
Code Examples
Code Examples
For VERSION3, all classes defined in the C++ Standard are put into namespace
std.
For VERSION2,several classes were in global namespace.
VERSION2 code for a simple “Hello world” program:
#include <iostream>
int main (void) {
cout << “Hello world” << endl;
}
One way to use VERSION3 for the “Hello world” program:
# include <iostream>
int main (void) {
std::cout << “Hello world” << std::endl;
}
Alternative VERSION3 code for the “Hello world” program:
#include <iostream>
using namespace std:
int main (void) {
cout << “Hello world” << endl;
}
If you compile the VERSION2 code as VERSION3, you will get two undefined identifiers
(cout and endl). Similar errors occur if you compile the VERSION3 source as
VERSION2.
To compile the “Hello world” program (file name test.cpp) using the
MIGRATION_CHECK pragma:
On OSS environment:
c89 test.cpp -Wversion2 -Wmigration_check -Wnosuppress
On Guardian:
nmcplus/ in testcpp, out $s.#list/ ; migration_check,
version2
The listing from MIGRATION_CHECK will contain:
5. 1 1 cout << “Hello world” << endl;
*** Warning: ^
--> (13) : ‘cout’ is in namespace std:: for version3