C H A P T E R  1

The C++ Compiler

This chapter provides information about the following:

1.1 New Features and Functionality of the Sun Studio 10 C++ 5.8 Compiler

This section provides a brief overview of the new C compiler features and functionality introduced in the Sun Studio 10 C++ 5.8 Compiler release. For specific explanations, follow the cross references provided for each item.

The -xarch option now supports the following new flags for development on the x86 platform: amd64a, pentium_proa, ssea, sse2a. See -xarch=isa.

The -xpagesize, -xpagesize_heap, -xpagesize_stack options are now enabled for x86 platforms as well as SPARC. See -xpagesize=n.

The new -xmodel option lets you specify the kernel, small, or medium memory models on the 64-bit AMD architecture. If the size of your global and static variables exceeds two gigabytes, specify -xmodel=medium. Otherwise, use the default -xmodel=small setting. See -xmodel=[a] for more information.

This release supports intrinsic functions for SSE2 128-bit XMM register integral media-instructions. Include the sunmedia_intrin.h header file in the source code and specify the -xbuiltin option to take advantage of these functions. Furthermore, these intrinsic functions require SSE2 support so specify options such as

          -xarch=sse2, -xarch=amd64, or -xtarget=opteron.

Essentially, the compiler generates inline code for these instrinsic functions. This is easier than manipulating the instructions through assembly language and it can be optimized by the compiler.

For more information about intrinsics, explanations for the function prototypes contained in the header files, and the data types used by these functions, see the 'Intel C++ Intrinsics Reference' section of the Intel(R) C++ Compiler for Linux Systems manual.

The -xvector option enables automatic generation of calls to the vector library functions and/or the generation of the SIMD (Single Instruction Multiple Data) instructions. See -xvector[=a] for more information.

A new -xbinopt option allows the compiler to prepare the binary file for further optimization by the binopt(1) binary optimizer. See -xbinopt={prepare|off} for more information.

The C++ standard says that function calls that depend on a template parameter can refer only to visible function declarations having external linkage. Specify -features=[no%]tmplrefstatic if your application code depends on the compiler ignoring this rule and calling a dependent static function from a function template. See -features=a[,a...] for more information and examples.

The new -xtarget flags ultra3iplus, ultra4plus, and ultraT1 along with the new -xchip flags ultra3iplus, ultra4plus, and ultraT1 provide code generation for the UltraSPARC IIIiplus, UltraSPARC T1, and UltraSPARC IVplus processors. See -xtarget=t and -xchip=c for more information.

The C++ compiler can now generate debugger information in the dwarf format. The default is still the stabs format, but you can generate dwarf data by setting the new option -xdebugformat to -xdebugformat=dwarf. See -xdebugformat=[stabs|dwarf].

The syntax of the STACKSIZE environment variable has been enhanced to accept a units keyword for denoting the slave thread stacksize: B for Bytes, K for Kilobytes, M for Megabytes, G for Gigabytes.

For example, setenv STACKSIZE 8192 sets the slave thread stack size to 8 MB. 1235B sets the slave thread stack size for 1235 Bytes. 1235G sets it for 1235 Gigabytes. The default for an integer value without a suffix letter is still Kilobytes.

Autoscoping is now available for C++ programs. This feature is described in chapter 3 of the Sun Studio OpenMP API User's Guide.

1.2 New Features and Functionality of the Sun Studio 10 C++ 5.7 Compiler

This section provides a brief overview of the new C++ compiler features and functionality introduced in the Sun Studio 10 C++ 5.7 Compiler release. For specific explanations, follow the cross references provided for each item.

Note - You must specify -xarch=amd64 to the right of -fast and -xtarget on the command line to generate 64-bit code. For example, specify CC -fast -xarch=amd64 or CC -xtarget=opteron -xarch=amd64. The new -xtarget=opteron option does not automatically generate 64-bit code. It expands to -xarch=sse2, -xchip=opteron, and -xcache=64/64/2:1024/64/16 which results in 32-bit code. The -fast option also results in 32-bit code because it is a macro which also defines -xtarget=native.

For more information about -xregs=[no%]frameptr, see Section A.2.160, -xregs=r[,r...].

Since MyClass<int> is a type, the code example does not use template-template parameters. However, in the following code example, the class template C has a parameter that is a class template, and object x is an instance of C using class template A as its argument. Member y of C has type A<int>.

// ordinary class template
template<typename T> class A {
    T x;  
// class template having a template parameter
template< template<typename U> class V > class C {
    V<int> y;
// instantiate C on template
C<A> x;

The C++ standard says that nested classes have no special access to members of the enclosing class. However, most people feel this restriction is not justified because member functions have access to private members, so member classes should too. In the following example, function foo tries to access a private member of class outer. According to the C++ standard, the function has no access unless it is declared a friend function:

class outer {
    int i; // private in outer
    class inner {
        int foo(outer* p) {
            return p->i; // invalid

The C++ Committee is in the process of adopting a change to the access rules giving the same access to member classes that member functions have. Many compilers have implemented this rule in anticipation of the changed language rule.

To restore the old compiler behavior, disallowing the access, use the compiler option -features=no%nestedaccess. The default is -features=nestedaccess. For more information on -features, see Section A.2.19, -features=a[,a...].

1.3 Standards Conformance

The C++ compiler (CC) supports the ISO International Standard for C++, ISO IS 14882:1998, Programming Language--C++. The readme file that accompanies the current release describes any departures from requirements in the standard.

On SPARCtrademark platforms, the compiler provides support for the optimization-exploiting features of SPARC V8 and SPARC V9, including the UltraSPARCtrademark implementation. These features are defined in the SPARC Architecture Manuals, Version 8 (ISBN 0-13-825001-4), and Version 9 (ISBN 0-13-099227-5), published by Prentice-Hall for SPARC International.

In this document, "Standard" means conforming to the versions of the standards listed above. "Nonstandard" or "Extension" refers to features that go beyond these versions of these standards.

The responsible standards bodies may revise these standards from time to time. The versions of the applicable standards to which the C++ compiler conforms may be revised or replaced, resulting in features in future releases of the Sun C++ compiler that create incompatibilities with earlier releases.

1.4 C++ Readme File

The C++ compiler's readme file highlights important information about the compiler, including:

To view the text version of the C++ readme file, type the following at a command prompt:

example% CC -xhelp=readme

To access the HTML version of the readme, in your Netscape Communicator 4.0 or compatible version browser, open the following file:


(If your C++ compiler-software is not installed in the /opt directory, ask your system administrator for the equivalent path on your system.) Your browser displays an index of HTML documents. To open the readme, find its entry in the index, then click the title.

1.5 Man Pages

Online manual (man) pages provide immediate documentation about a command, function, subroutine, or collection of such things.

You can display a man page by running the command:

example% man topic

Throughout the C++ documentation, man page references appear with the topic name and man section number: CC(1) is accessed with man CC. Other sections, denoted by ieee_flags(3M) for example, are accessed using the -s option on the man command:

example% man -s 3M ieee_flags

1.6 C++ Utilities

The following C++ utilities are now incorporated into traditional UNIX® tools and are bundled with the UNIX operating system:

See Program Performance Analysis Tools and associated man pages for further information on these UNIX tools.

1.7 Native-Language Support

This release of C++ supports the development of applications in languages other than English, including most European languages and Japanese. As a result, you can easily switch your application from one native language to another. This feature is known as internationalization.

In general, the C++ compiler implements internationalization as follows:

Variable names cannot be internationalized and must be in the English character set.

You can change your application from one native language to another by setting the locale. For information on this and other native-language support features, see the operating system documentation.