C H A P T E R  1

Introduction to the C Compiler

This chapter provides information about the C compiler, including operating environments, standards conformance, organization of the compiler, and C-related programming tools.


1.1 Standards Conformance

The compiler conforms to the following standards:

This release also supports some of the features specified in the following standard:

Because the compiler also supports traditional K&R C (Kernighan and Ritchie, or pre-ANSI C), it can ease your migration to ISO C.

The term C99 used in this book refers to the ISO/IEC 9899:1999 C programming language. There term C90 refers to the ISO/IEC 9899:1990 C programming language.


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 New Features

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

1.4.1 General Enhancements

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 scoping by specifying -xldscope at the command line.

For details, see Linker Scoping Specifiers and -xldscope={v}.

This release adds support for the following ISO/IEC 9899:1999 (referred to as C99 in this document) features. The following list only details the C99 features implemented in this release, which is a subset of all the implemented C99 features. See Appendix D Supported Features of C99 for a complete listing of all C99 features implemented over the past and current release of the C compiler. The sub-section number of the C99 standard is listed for each item.

This release supports a partial implementation of _Complex. You must link with -lcplxsupp on the Solaris 7 operating environment, the Solaris 8 operating environment, and the Solaris 9 operating environment. Static initialization of _Complex data does not yet work.

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

The default stack size for slave threads is now larger. All slave threads have the same stack size, which is four megabytes for 32-bit applications and eight megabytes for 64-bit applications by default. The size is set with the STACKSIZE environment variable.

See STACKSIZE.

The -xprofile option offers the following improvements:

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.

Specify -xustr=ascii_utf16_ushort if you need to support an internationalized application that uses ISO10646 UTF-16 string literals. This option enables recognition of the U"ASCII_string" string literals as an array of type unsigned short.

See -xustr={ascii_utf16_ushort|no}.

See -Xustr={ascii_utf16_ushort|no} for the equivalent option to the lint utility.

1.4.2 Faster Compilation

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

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

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.4.3 Improved Performance

Use the new linker supported thread-local storage facility of the compiler to do the following:

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.

For more information, see Thread Local Storage Specifier and -xthreadvar[=o].

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:

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

Set the page size in memory for the stack. 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 at the target platform.



Note - This feature is only available on Solaris 9 software. 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.

Use the -xhwcprof=[enable|disable] option to enable compiler support for hardware counter-based profiling.

When -xhwcprof is enabled, the compiler generates information that helps tools match hardware counter data reference and miss events with associated instructions. Corresponding data-types and structure-members may also be identified in conjunction with symbolic information (produced with -g). This information can be useful in performance analysis because it is not easily identified from profiles based on code addresses, source statements, or routines.

See -xhwcprof.

1.4.4 Easier Debugging

The C compiler is migrating the format of debugger information from the stabs format to the dwarf format as specified in DWARF Debugging Information Format. If you maintain software which reads debugging information, you now have the option to transition your tools from the stabs format to the dwarf format. The default setting for this release is -xdebugformat=stabs.

Use the -xdebugformat=dwarf option as a way of accessing the new format for the purpose of porting tools. There is no need to use this option unless you maintain software which reads debugger information, or unless a specific tool tells you that it requires debugger information in one of these formats.

See -xdebugformat=[stabs|dwarf].

If you are debugging an OpenMP program with dbx, compile with -g and -xopenmp=noopt so you can breakpoint within parallel regions and display the contents of variables.

See -xopenmp[=i].


1.5 Organization of the Compiler

The C compilation system consists of a compiler, an assembler, and a link editor. The cc command invokes each of these components automatically unless you use command-line options to specify otherwise.

Appendix A discusses all the options available with cc.

The following figure shows the organization of the C compilation system.

 FIGURE 1-1 Organization of the C Compilation System

Diagram showing the components of the C compilation system.[ D ]

The following table summarizes the components of the compilation system.

TABLE 1-1 Components of the C Compilation System

Component

Description

Notes on Use

cpp

Preprocessor

-Xs only

acomp

Compiler (preprocessor built in for non-Xs modes)

 

ssbd

Static synchronization bug detection

(SPARC)

iropt

Code optimizer

(SPARC) -O, -xO2, -xO3, -xO4, -xO5, -fast

fbe

Assembler

 

cg

Code generator, inliner, assembler

(SPARC)

ipo

Interprocedural Optimizer

(SPARC)

postopt

Postoptimizer

(SPARC)

ir2hf

Intermediate code translator

(INTEL)

ube

Code generator

(INTEL)

ube_ipa

Interprocedure analyzer

(INTEL)

ld

Linker

 

ild

Incremental linker

(SPARC) -g, -xildon

mcs

Manipulate comment section

-mr



1.6 C-Related Programming Tools

There are a number of tools available to aid in developing, maintaining, and improving your C programs. The two most closely tied to C, cscope and lint, are described in this book. In addition, a man page exists for each of these tools.

Other tools for source browsing, debugging and performance analysis are available. See Accessing Compilers and Tools Documentation for more information.