C H A P T E R  1

The C++ Compiler

This chapter provides a brief conceptual overview of the C++ compiler.


1.1 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.2 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:

/opt/SUNWspro/docs/index.html

(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.3 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.4 Licensing

The C++ compiler uses network licensing, as described in the Installation Guide.

If you invoke the compiler, and a license is available, the compiler starts. A single license can be used for any number of simultaneous compiles by a single user on a single machine.

To run C++ and the various utilities, several licenses might be required, depending on the package you have purchased.


1.5 New Features of the C++ Compiler

The C++ compiler introduces the following new features in this release.

1.5.1 General Enhancements

  • Template cache no longer needed: -instances
This release of the C++ compiler improves template instantiation significantly. Programs that use the default template instantiation model are no longer restricted from building more than one program in a directory.
Most programs that rely on an alternate instantiation model, such as -instances=static, can now use the new default instantiation model.
The improvements and changes to template instantiation will either improve compile time by avoiding a template cache, or reduce executable size by avoiding duplicate static functions.
For details, see -instances=a.
  • Linker mapfiles no longer needed for variable scoping: -xldscope
There are now two different ways you can control the exporting of symbols in dynamic libraries. This facility is called linker scoping, and has been supported by linker mapfiles for some time. First, you can now embed new declaration specifiers in code.
By embedding __global, __symbolic, and __hidden directly in code, you no longer need to use mapfiles. Second, you can override the default setting for variable scopping by specifying -xldscope at the command line.
See -xldscope={v}. The declaration specifiers are detailed in Linker Scoping.
  • Powerful new diagnostics for macros: -xdumpmacros
This release introduces two new pragmas and a new compiler option designed to help you track the behavior of macros in your application. This includes macros defined in system headers.
You can use the -xdumpmacros option at the command line to see the macro definitions and also to see where macros are defined, undefined, and used in your program. To narrow your focus, use the new dumpmacros and end_dumpmacros pragmas directly in the source.
See -xdumpmacros[=value[,value...]], #pragma dumpmacros. and #pragma end_dumpmacros.
  • Support for VIS[tm] Developers Kit: -xvis (SPARC)
Use the -xvis=[yes|no] option when you are using the assembly-language templates defined in the VIS instruction set Software Developers Kit (VSDK). The default is -xvis=no.
The VIS instruction set is an extension to the SPARC v9 instruction set. Even though the UltraSPARC processors are 64-bit, there are many cases, especially in multimedia applications, when the data are limited to eight or 16 bits in size. The VIS instructions can process four 16-bit data with one instruction so they greatly improve the performance of applications that handle new media such as imaging, linear algebra, signal processing, audio, video and networking.
For more information on the VSDK, see http://www.sun.com/processors/vis . See -xvis[={yes|no}].
  • Support for C99 runtime libraries and environment: -xlang=c99
On operating systems that support the C99 standard (ISO/IEC 9899:1999, Programming Language - C), -xlang=c99 specifies C99 runtime behavior for C and C++ code that invokes C library functions. Some C99 behavior, like the C complex type, depends on the use of the -xc99=%all option with the C compiler, and some behavior, like printf, does not.


Note - C99 support is not available in compat mode (-compat=4).



See -xlang=language[,language].
  • Support for UTF-16 string literals: -xustr
Specify -xustr=ascii_utf16_ushort if you need to support an internationalized application that uses ISO10646 UTF-16 string literals. In other words, use this option if your code contains a string literal composed of sixteen-bit characters. Without this option, the compiler neither produces nor recognizes sixteen-bit character string literals. This option enables recognition of the U"ASCII_string" string literals as an array of type unsigned short. Since such strings are not yet part of any standard, this option enables recognition of non-standard C++.
See -xustr={ascii_utf16_ushort|no}.
  • Expanded support for OpenMP: -xopenmp
The C++ compiler continues its implementation of the OpenMP interface for explicit parallelization.
The compiler has expanded OpenMP functionality to allow the following:
    • Class objects are permitted in OpenMP data clauses.
    • OpenMP pragmas are permitted in class member functions.
See -xopenmp[=i] for more information about the compiler command for OpenMP. See OpenMP API User's Guide for more information about the OpenMP C++ application program interface (API) for building multiprocessing applications.
  • Improved -xprofile (SPARC)
The -xprofile option offers the following improvements:
    • Support for profiling shared libraries
    • Thread-safe profile collection using -xprofile=collect -mt
    • Improved support for profiling multiple programs in a single profile directory.
With -xprofile=use, the compiler can now find profile data in profile directories that contain data for multiple object files with nonunique basenames. For cases where the compiler is unable to find an object file's profile data, the compiler provides a new option -xprofile_pathmap=collect-prefix: use-prefix.
See -xprofile=p and -xprofile_pathmap.

1.5.2 Faster Compilation

  • Speeding up syntax checking: -xe
When you specify -xe, the compiler checks only for syntax and semantic errors and does not produce any object code.
Use the -xe option if you do not need the object files produced by compilation. For example, if you are trying to isolate the cause of an error message by deleting sections of code, you can speed the edit and compile cycle by using -xe.
See -xe.
  • Faster profiling with -xprofile_ircache
Use -xprofile_ircache[=path] with -xprofile=collect|use to improve compilation time during the use phase by reusing compilation data saved from the collect phase.
With large programs, compilation time in the use phase can improve significantly because the intermediate data is saved. Note that the saved data could increase disk space requirements considerably.
See -xprofile_ircache[=path].
  • Stopping redundant template instantiations: -instlib=filename
Use -instlib=filename to inhibit the generation of template instances that are duplicated in a library and the current object. In general, if your program shares large numbers of instances with libraries, try -instlib=filename and see whether or not compilation time improves.
See -instlib=filename.
  • Generating functions with -template=geninlinefuncs
Usually, the C++ compiler will not generate an inline template function unless the function is called and cannot be inlined. However, you can specify -template=geninlinefuncs and the compiler instantiates inline member functions of the explicitly instantiated class template which were not generated previously. Linkage for these functions is local in all cases.
See -template=opt[,opt...].
  • Precpompiled headers, -xpch
This release of the compiler introduces the new precompiled-header feature. The precompiled-header file is designed to reduce compile time for applications whose source files share a common set of include files containing a large amount of source code. A precompiled header works by collecting information about a sequence of header files from one source file, and then using that information when recompiling that source file, and when compiling other source files that have the same sequence of headers. You can take advantage of this feature through the -xpch and -xpchstop options in combination with the #pragma hdrstop directive.
See -xpch=v, -xpchstop=file, and #pragma hdrstop.
  • Using multiple processors with -xjobs=n (SPARC)
Specify the -xjobs=n option to set how many processes the compiler creates to complete its work. This option can reduce the build time on a multi-cpu machine. Currently, -xjobs works only with the -xipo option. When you specify -xjobs=n, the interprocedural optimizer uses n as the maximum number of code generator instances it can invoke to compile different files.
See -xjobs=n.

1.5.3 Easier Porting

  • Simplify porting: -xmemalign
Use the -xmemalign option to control the assumptions the compiler makes about the alignment of data. By controlling the code generated for potentially misaligned memory accesses and by controlling program behavior in the event of a misaligned access, you can more easily port your code to the Solaris operating environment.
See -xmemalign=ab.
  • Setting the sign of char: -xchar
The -xchar[={signed|s|unsigned|u}] option is provided solely for the purpose of easing the migration of code from systems where the char type is defined as unsigned. Do not use this option unless you are migrating from such a system. Only code that relies on the sign of a char type needs to be rewritten to explicitly specify signed or unsigned.
See -xchar[=o].
  • Debugging ported code: -xport64
Use the new -xport64 option to help you port code to a 64-bit environment. Specifically, this option warns against problems such as truncation of values (including pointers), sign extension, and changes to bit-packing that are common when you port code from a 32-bit architecture such as V7 (ILP32) to a 64-bit architecture such as V9 (LP64).
See -xport64[=(v)].

1.5.4 Improved Performance

  • Improving run-time with linker supported thread-local storage of data: -xthreadvar (SPARC)
Use the new linker supported thread-local storage facility of the compiler to do the following:
    • Utilize a fast implementation for the POSIX interfaces for allocating thread-specific data.
    • Convert multi-process programs to multi-thread programs.
    • Port Windows applications using thread-local storage to the Solaris operating environment.
    • Utilize a fast implementation for the threadprivate variables in OpenMP.
Thread-local storage is now available in the compiler through the declaration of thread-local variables. The declaration consists of a normal variable declaration with the addition of the variable specifier __thread and the command line option -xthreadvar.
See -xthreadvar[=o]. The declaration specifiers are detailed in Thread-Local Storage.
  • Improving run-time by reducing page faults: -xF
Use the new functionality of -xF to enable the optimal reordering of variables and functions by the linker. This can help solve the following problems which negatively impact run-time performance:
    • Cache and page contention caused by unrelated variables that are near each other in memory.
    • Unnecessarily large work-set size as a result of related variables which are not near each other in memory.
    • Unnecessarily large work-set size as a result of unused copies of weak variables that decrease the effective data density.
See -xF[=v[,v...]].
  • Improving run-time with new pragmas
The C++ compiler now supports four new pragmas that you can use to help improve the optimization of your code:
See Pragmas.
  • Improving run-time with the link-time optimizer: -xlinkopt
The C++ compiler can now perform link-time optimization on relocatable object files when you specify the -xlinkopt command.
Specify -xlinkopt and the compiler performs some additional optimizations at link time without modifying the .o files that are linked. The optimizations appear only in the executable program. The -xlinkopt option is most effective when you use it to compile the whole program, and with profile feedback.
See -xlinkopt[=level].
  • Improving run-time with -xpagesize=n (SPARC)
Use the -xpagesize=n option to set the preferred page size for the stack and the heap. n can be 8K, 64K, 512K, 4M, 32M, 256M, 2G, 16G, or default. You must specify a valid page size for the Solaris operating environment on the target platform, as returned by getpagesize(3C). If you do not specify a valid page size, the request is silently ignored at run-time. You can use pmap(1) or meminfo(2) to determine page size of the target platform.


Note - This feature is only available on the Solaris 9 operating environment. A program compiled with this option will not link in earlier Solaris operating environments.



This option is a macro for -xpagesize_stack and -xpagesize_heap.
See -xpagesize=n, -xpagesize_heap=n, and -xpagesize_stack=n.

1.5.5 Added Warning and Error Controls

  • Filtering warning messages with -erroff
Use the new -erroff option to suppress warning messages from the compiler front-end. Note that neither error messages nor messages from the driver are affected. You can also use -erroff to single out a particular warning message so that either it alone is suppressed or it alone is issued.
For example, -erroff=tag suppresses the warning message specified by this tag. On the other hand, -erroff=%all,no%tag suppresses all warning messages except the messages identified by tag. You can display the tag for a warning message by using the -errtags=yes option.
See -erroff[=t].
  • Aborting compilation with -errtags and -errwarn
Use the -errtags and -errwarn compiler options to stop compilation if the compiler issues a particular warning. Set -errtags=yes to find the tag for a particular warning and then specify -errwarn=tag where tag is the unique identifier returned by -errtags for a particular warning message.
You can also abort compilation if any warning is issued by specifying -errwarn=%all.
See -errtags[=a] and -errwarn[=t].
  • Improved filtering for standard-library names with -filt=[no%]stdlib
The -filt=[no%]stdlib option is set by default and simplifies names from the standard library in both the linker and compiler error messages. This makes it easier for you to recognize the name of standard-library functions. Specify -filt=no%stdlib disable this filtering.
See -filt[=filter[,filter...]].


1.6 C++ Utilities

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

  • lex--Generates programs used in simple lexical analysis of text
  • yacc--Generates a C function to parse the input stream according to syntax
  • prof--Produces an execution profile of modules in a program
  • gprof--Profiles program runtime performance by procedure
  • tcov--Profiles program runtime performance by statement

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:

  • C++ recognizes ASCII characters from international keyboards (in other words, it has keyboard independence and is 8-bit clean).
  • C++ allows the printing of some messages in the native language.
  • C++ allows native-language characters in comments, strings, and data.
  • C++ supports only Extended UNIX Character (EUC) compliant character sets - a character set in which every null byte in a string is the null character and every byte in the string with the ascii value of '/' is the '/' character.

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 environment documentation.