C++ Migration Guide

Preface

This book explains what you need to know when moving from 4.0, 4.0.1, 4.1, or 4.2 versions of the C++ compiler to the C++ 5.0 version. If you are moving from still earlier 3.0 or 3.0.1 versions of the C++ compiler, the information still applies. A few additional topics specific to these older compiler versions are addressed.

Who Should Use This Book

This manual is intended for programmers with a working knowledge of C++ and some understanding of the Solaris(TM) operating environment and UNIX® commands.

How This Book Is Organized

This book contains the following chapters:

Chapter 1, "Introduction," discusses the C++ language changes, the compiler compatibility modes, binary compatibility issues, conditional expressions, and function pointers and void*.

Chapter 2, "Using Compatibility Mode," describes the minor differences between using the C++ 4.0, 4.1, or 4.2 compiler and using the C++ 5.0 compiler.

Chapter 3, "Using Standard Mode," explains the C++ 5.0 compiler changes.

Chapter 4, "Using Libraries and Header Files," explains library and header file changes in the C++ 5.0 compiler.

Chapter 5, "Migrating from C++ 3.0 to C++ 5.0," discusses migration from the C++ 3.0 compilers to the C++ 5.0 compiler.

Chapter 6, "Moving from C to C++," describes how to move programs from C to C++.

Multiplatform Release

The SunTM WorkShopTM C++ compiler documentation applies to the release of the C++ compiler on Solaris 2.5.1, 2.6, and Solaris 7 operating environments on:

C++ Books

The following books are part of the C++ 5.0 documentation package.

Other Sun WorkShop Books

The following books are part of the Sun Visual WorkShop C++ documentation package:

Solaris Books

The following Solaris manuals and guides provide additional useful information:

Commercially Available Books

The following is a partial list of available books on the C++ language.

Object-Oriented Analysis and Design with Applications, Second Edition, Grady Booch (Addison-Wesley, 1994)

Thinking in C++, Bruce Eckel (Prentice Hall, 1995)

The Annotated C++ Reference Manual, Margaret A. Ellis and Bjarne Stroustrup (Addison-Wesley, 1990)

Design Patterns: Elements of Reusable Object-Oriented Software, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, (Addison-Wesley, 1995)

C++ Primer, Third Edition, Stanley B. Lippman and Josee Lajoie (Addison-Wesley, 1998)

Effective C++-50 Ways to Improve Your Programs and Designs, Second Edition, Scott Meyers (Addison-Wesley, 1998)

More Effective C++-35 Ways to Improve Your Programs and Designs, Scott Meyers (Addison-Wesley, 1996)

STL Tutorial and Reference Guide-Programming with the Standard Template Library, David R. Musser and Atul Saini (Addison-Wesley, 1996)

C++ for C Programmers, Ira Pohl (Benjamin/Cummings, 1989)

The C++ Programming Language, Third Edition, Bjarne Stroustrup (Addison-Wesley, 1997)

Ordering Sun Documents

The SunDocsSM program provides more than 250 manuals from Sun Microsystems, Inc. If you live in the United States, Canada, Europe, or Japan, you can purchase documentation sets or individual manuals using this program.

For a list of documents and how to order them, see the catalog section of the SunExpress(TM) Internet site at http://www.sun.com/sunexpress.

Accessing Sun Documents Online

Online documentation includes: online books, man pages, command-line help and README files. These are described below.

Online Books

The docs.sun.com Web site enables you to access Sun technical documentation online. You can browse the docs.sun.com archive or search for a specific book title or subject. The URL is http://docs.sun.com/.

The Sun WorkShop documentation is also available using AnswerBook(TM) software. To access the AnswerBook collections, your system administrator must have installed the AnswerBook package during the installation process. For information on installing and accessing AnswerBook software see the Sun WorkShop installation documentation, the Solaris installation documentation, or your system administrator.

This release of Sun WorkShop includes an online help system as well as online manuals. To find out more see:

Man Pages

Online man pages provide immediate documentation about a command or library function. You can display a man page by running the command:


demo% man topic

Man pages are in:

opt-install-dir/SUNWspro/man

The following table lists and describes the C++ man pages.


Note -

Before you use the man command, at the beginning of your search path, insert the name of the directory in which you have chosen to install the C++ compiler. This enables you to use the man command. This is usually done in the .cshrc file, in a line with setenv MANPATH at the start; or in the .profile file, in a line with export MANPATH at the start.


Table P-1 C++ Man Pages

Title 

Description 

CC 

Describes the C++ compiler command line options 

CCadmin

Cleans the templates database. Provides information about mangled names and symbols in the templates database 

cartpol

Provides Cartesian/polar functions in the C++ complex number math library 

cplx.intro

Introduces the C++ complex number math library 

cplxerr

Provides complex error-handling functions in the C++ complex number math library 

cplxops

Provides arithmetic operator functions in the C++ complex number math library 

cplextrig

Provides trigonometric operator functions in the C++ complex number math library 

demangle

Decodes a C++ encoded symbol name 

filebuf

Buffer class for file I/O 

fstream

Provides stream class for file I/O 

istream

Supports formatted and unformatted input 

ios

Provides basic iostream formatting 

ios.intro

Introduces iostream man pages 

manip

Provides iostream manipulators 

ostream

Supports formatted and unformatted output 

queue

Provides list management for task library 

sbufprot

Provides protected interface of streambuffer base class 

sbufpub

Provides public interface of streambuffer base class 

sigfpe

Allows signal handling for specific SIGFPE codes 

ssbuf

Provides buffer class for character arrays 

stdarg

Handles variable argument list 

stdiobuf

Provides buffer and stream classes for use with C stdio 

stream_locker

Provides class used for application level locking of iostream class object 

stream_MT

Base class that provides dynamic changing of iostream class object to and from MT safely 

strstream

Provides stream class for "I/O" using character arrays 

varargs

Handles variable argument list 

vector

Provides generic vector and stack 

The following table lists man pages that contain information related to the C++ compiler.

Table P-2 C++-Related Man Pages

Title 

Description 

c++filt

Copies each file name in sequence and writes it in the standard output after decoding symbols that look like C++ demangled names. 

dem

Demangles one or more C++ names that you specify 

fbe

Creates object files from assembly language source files. 

fpversion

Prints information about the system CPU and FPU 

gprof

Produces execution profile of a program 

ild

Links incrementally, allowing insertion of modified object code into a previously built executable 

inline

Expands assembler inline procedure calls 

lex

Generates lexical analysis programs 

rpcgen

Generates C/C++ code to implement an RPC protocol 

version

Displays version identification of object file or binary 

yacc

Converts a context-free grammar into a set of tables for a simple automaton that executes an LALR(1) parsing algorithm 

README file

The README file highlights important information about the compiler, including:

README files are in:

opt-install-dir/SUNWspro/READMEs

View the C++ README file by typing


%CC -readme

What Typographic Changes Mean

The following table describes the typographic changes used in this book.

Table P-3 Typographic Conventions

Typeface or Symbol 

Meaning 

Example 

AaBbCc123

The names of commands, files, and directories; on-screen computer output 

Edit your .login file.

Use ls -a to list all files.

machine_name% You have mail.

 

AaBbCc123

What you type, contrasted with on-screen computer output 

machine_name% su

Password:

AaBbCc123

Command-line placeholder: 

replace with a real name or value 

To delete a file, type rm filename.

AaBbCc123

Book titles, new words or terms, or words to be emphasized 

Read Chapter 6 in User's Guide. These are called class options.

You must be root to do this.

Compiler options and code samples may use the following conventions: 

[ ]

 

Square brackets contain arguments that are optional. 

-xO[n]

 

( ) 

Parentheses contain a set of choices for a required option. 

-d(y|n) 

|

 

The "pipe" or "bar" symbol separates arguments, only one of which may be used at one time. 

-d(y|n) 

 

 

...

 

The ellipsis indicates omission in a series. 

-xinline=f1[,...fn]

 

%

 

The percent sign indicates the word has a special meaning.  

-ftrap=%all, no%division

 

<>

 

In ASCII files, such as the README file, angle brackets contain a variable that must be replaced by an appropriate value.

-xtemp=<dir>

 

Shell Prompts in Command Examples

The following table shows the default system prompt and superuser prompt for the C shell, Bourne shell, and Korn shell.

Table P-4 System Prompts

Shell 

Prompt 

C shell prompt 

machine_name%

C shell superuser prompt 

machine_name#

Bourne shell and Korn shell prompt 

$

Bourne shell and Korn shell superuser prompt 

#