Sun Logo


C++ Migration Guide

Suntrademark Studio 10

819-0495-10



Contents

Tables

Code Samples

Before You Begin

Typographic Conventions

Shell Prompts

TABLE P-2 Supported Platforms -xii

Accessing Sun Studio Software and Man Pages

Accessing Compilers and Tools Documentation

Accessing Related Solaris Documentation

Commercially Available Books

Resources for Developers

Contacting Sun Technical Support

Sending Your Comments

1. Introduction

1.1 The C++ Language

1.2 Compiler Modes of Operation

1.2.1 Standard Mode

1.2.2 Compatibility Mode

1.3 Binary Compatibility Issues

1.3.1 Language Changes

1.4 Mixing Old and New Binaries

1.4.1 Getting Started

1.4.2 Requirements

1.4.3 Structuring the Interface

1.5 Conditional Expressions

1.6 Function Pointers and void*

1.7 Anticipating Future Mangling Changes

1.7.1 Symptoms of Improper Mangling

2. Using Compatibility Mode

2.1 Compatibility Mode

2.2 Keywords in Compatibility Mode

2.3 Language Semantics

2.3.1 Copy Constructor

2.3.2 Static Storage Class

2.3.3 Operators new and delete

2.3.4 new const

2.3.5 Conditional Expression

2.3.6 Default Parameter Value

2.3.7 Trailing Commas

2.3.8 Passing of const and Literal Values

2.3.9 Conversion Between Pointer-to-Function and void*

2.3.10 Type enum

2.3.11 Member-Initializer List

2.3.12 const and volatile Qualifiers

2.3.13 Nested Type

2.3.14 Class Template Definitions and Declarations

2.4 Template Compilation Model

3. Using Standard Mode

3.1 Standard Mode

3.2 Keywords in Standard Mode

3.3 Templates

3.3.1 Resolving Type Names

3.3.2 Converting to the New Rules

3.3.3 Explicit Instantiation and Specialization

3.3.4 Class Template Definitions and Declarations

3.3.5 Template Repository

3.3.6 Templates and the Standard Library

3.4 Class Name Injection

3.5 for-Statement Variables

3.6 Conversion Between Pointer-to-Function and void*

3.7 String Literals and char*

3.8 Conditional Expressions

3.9 New Forms of new and delete

3.9.1 Array Forms of new and delete

3.9.2 Exception Specifications

3.9.3 Replacement Functions

3.9.4 Header Inclusions

3.10 Boolean Type

3.11 Pointers to extern "C" Functions

3.11.1 Language Linkage

3.11.2 A Less-Portable Solution

3.11.3 Pointers to Functions as Function Parameters

3.12 Runtime Type Identification (RTTI)

3.13 Standard Exceptions

3.14 Order of the Destruction of Static Objects

4. Using Iostreams and Library Headers

4.1 Iostreams

4.2 Task (Coroutine) Library

4.3 Rogue Wave Tools.h++

4.4 C Library Headers

4.5 Standard Header Implementation

5. Moving From C to C++

5.1 Reserved and Predefined Words

5.2 Creating Generic Header Files

5.3 Linking to C Functions

5.4 Inlining Functions in Both C and C++

6. Workarounds for 4.0, 4.1, and 4.2 Compilers

6.1 Problems and Solutions

6.1.1 Cache Version Differences May Cause Compilation Errors

6.1.2 Interface Incompatibilities

6.1.3 Tools.h++

6.1.4 Multiple Template Repositories

6.1.5 Linking With 4.0.1 Libraries Containing Pointers to const Member Functions

6.1.6 Linking With Libraries Compiled With Earlier Compilers

6.1.7 Mixing Object Code From Different Versions

Index