Sun Studio 12: C++ User's Guide


This manual instructs you in the use of the C++ compiler for SunTM Studio 12 and provides detailed information on command-line compiler options. This manual is intended for programmers with a working knowledge of C++ and some understanding of the SolarisTM Operating System and UNIX® commands.

How This Book Is Organized

This manual covers the following topics:

C++ Compiler. Sending Your Comments provides introductory material about the compiler, such as standards conformance and new features.1.6 Native-Language Support explains how to use the compiler and Using make With Standard Library Header Files discusses how to use the compiler’s command line options.

Writing C++ Programs. Table 3–18 discusses how to compile nonstandard code that is commonly accepted by other C++ compilers. 4.10 Using the Predefined __func__ Symbol for Function Name makes suggestions for setting up and organizing header files and template definitions. 5.2.2 Template Definitions Separate discusses how to create and use templates and 6.7.7 Building Multiple Programs Using Templates in the Same Directory explains various options for compiling templates. Exception handling is discussed in 7.5.3 Troubleshooting a Problematic Search and information about cast operations is provided in 8.6 Building Shared Libraries That Have Exceptions. 9.4.3 Casting Down or Across the Hierarchy discusses performance techniques that strongly affect the C++ compiler. 10.5 Cache Member Variables provides information about building multithreaded programs.

Libraries. 11.4.8 An Example Application explains how to use the libraries that are provided with the compiler. The C++ standard library is discussed in Caveats:, the classic iostream library (for compatibility mode) is discussed in 13.3.1 Redistribution and Supported STLport Libraries, and the complex arithmetic library (for compatibility mode) is discussed in Table 14–4. Table 15–3 provides information about building libraries.

Appendices. 16.8 Using dlopen to Access a C++ Library From a C Program lists the complete set of C++ compiler options in alphabetic order and A.2.185 -z[ ]arg lists the C++ compiler pragmas.

Typographic Conventions

Table P–1 Typeface Conventions Table





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

Edit your .login file.

Use ls -a to list all files.

% You have mail.


What you type, when contrasted with on-screen computer output 

% su



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

Read Chapter 6 in the User’s Guide.

These are called class options.

You must be superuser to do this.


Command-line placeholder text; replace with a real name or value 

To delete a file, type rm filename.

Table P–2 Code Conventions Table

Code Symbol 



Code Example 

[ ] 

Brackets contain arguments that are optional. 


O4, O

{ } 

Braces contain a set of choices for a required option. 



The “pipe” or “bar” symbol separates arguments, only one of which may be chosen. 



The colon, like the comma, is sometimes used to separate arguments. 




The ellipsis indicates omission in a series. 



Shell Prompts



C shell 


C shell superuser 


Bourne shell, Korn shell, and GNU Bourne-Again shell 


Superuser for Bourne shell, Korn shell, and GNU Bourne-Again shell 


Supported Platforms

This Sun Studio release supports systems that use the SPARC® and x86 families of processor architectures: UltraSPARC®, SPARC64, AMD64, Pentium, and Xeon EM64T. The supported systems for the version of the Solaris Operating System you are running are available in the hardware compatibility lists at These documents cite any implementation differences between the platform types.

In this document, these x86 related terms mean the following:

For supported systems, see the hardware compatibility lists.

Accessing Sun Studio Documentation

You can access the documentation at the following locations:

The web site ( enables you to read, print, and buy Sun Microsystems manuals through the Internet. If you cannot find a manual, see the documentation index that is installed with the software on your local system or network.

Note –

Sun is not responsible for the availability of third-party Web sites mentioned in this document. Sun does not endorse and is not responsible or liable for any content, advertising, products, or other materials that are available on or through such sites or resources. Sun will not be responsible or liable for any actual or alleged damage or loss caused by or in connection with the use of or reliance on any such content, goods, or services that are available on or through such sites or resources.

Documentation in Accessible Formats

The documentation is provided in accessible formats that are readable by assistive technologies for users with disabilities. You can find accessible versions of documentation as described in the following table. If your software is not installed in the /opt directory, ask your system administrator for the equivalent path on your system.

Type of Documentation 

Format and Location of Accessible Version  

Manuals (except third-party manuals) 


Third-party manuals: 

  • Standard C++ Library Class Reference

  • Standard C++ Library User’s Guide

  • Tools.h++ Class Library Reference

  • Tools.h++ User’s Guide

HTML in the installed software on Solaris platforms through the documentation index at file:/opt/SUNWspro/docs/index.html


HTML on the Sun Developer Network portal at

Man pages 

HTML in the installed software through the documentation index at file:/opt/SUNWspro/docs/index.html on Solaris platforms, and at file:/opt/sun/sunstudio12/docs/index.html on Linux platforms,

Online help 

HTML available through the Help menu and Help buttons in the IDE 

Release notes 


Related Sun Studio Documentation

The following table describes related documentation that is available at file:/opt/SUNWspro/docs/index.html and If your software is not installed in the /opt directory, ask your system administrator for the equivalent path on your system.

Document Title 


C User's Guide

Provides a reference of all compiler options, descriptions of supported ISO/IEC 9899:1999 (referred to as C99) features, implementation specifics such as pragmas and declaration specifiers, and complete information for using the lint code-checking program.

C++ User's Guide

Describes how to use the C++ compiler and provides detailed information on command-line compiler options, program organization, pragmas, templates, exception handing, using the cast operators, and using and building libraries. 

Fortran Programming Guide

Describes how to write effective Fortran programs on Solaris environments; input/output, libraries, performance, debugging, and parallelization. 

Fortran Library Reference

Details the Fortran library and intrinsics. 

OpenMP API User’s Guide

Summary of the OpenMP multiprocessing API, with specifics about the implementation. 

Numerical Computation Guide

Describes issues regarding the numerical accuracy of floating-point computations. 

Accessing C++ Related Man Pages

This manual provides lists of the man pages that are available for the C++ libraries. The following table lists other man pages that are related to C++.




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


Demangles one or more C++ names that you specify 


Creates object files from assembly language source files 


Prints information about the system CPU and FPU 


Produces execution profile of a program 


Expands assembler inline procedure calls 


Generates lexical analysis programs 


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


Allows signal handling for specific SIGFPE codes 


Handles variable argument list 


Handles variable argument list 


Displays version identification of object file or binary 


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

Accessing Related Solaris Documentation

The following table describes related documentation that is available through the web site.

Document Collection 

Document Title 


Solaris Reference Manual Collection 

See the titles of man page sections. 

Provides information about the Solaris OS. 

Solaris Software Developer Collection 

Linker and Libraries Guide

Describes the operations of the Solaris link-editor and runtime linker. 

Resources for Developers

Visit the Sun Developer Network Sun Studio portal at to find these frequently updated resources:

The Sun Studio portal is one of a number of additional resources for developers at the Sun Developer Network website,

Commercially Available Books

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

The C++ Programming Language 3rd edition, Bjarne Stroustrup (Addison-Wesley, 1997).

The C++ Standard Library, Nicolai Josuttis (Addison-Wesley, 1999).

Generic Programming and the STL, Matthew Austern (Addison-Wesley, 1999).

Standard C++ IOStreams and Locales, Angelika Langer and Klaus Kreft (Addison-Wesley, 2000).

Thinking in C++, Volume 1, Second Edition, Bruce Eckel (Prentice Hall, 2000).

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

Contacting Sun Technical Support

If you have technical questions about this product that are not answered in this document, go to:

Sending Your Comments

Sun is interested in improving its documentation and welcomes your comments and suggestions. Submit your comments to Sun at this URL:

Please include the part number of the document in the subject line of your email. For example, the part number for this document is 819-5267-10.