Sun Studio 12 Update 1: C User's Guide

Chapter 1 Introduction to the C Compiler

This chapter provides basic information about the Sun Studio C compiler.

1.1 What's New in Version 5.10 Sun Studio 12 Update 1 Release

Note the following new and changed features in the current C compiler release.

1.2 Special x86 Notes

There are some important issues to be aware of when compiling for x86 Solaris platforms.

The legacy Sun-style parallelization pragmas are not available on x86. Use OpenMP instead. See the Sun Studio OpenMP API User’s Guide for information on converting legacy parallelization directives to OpenMP.

Programs compiled with -xarch set to sse, sse2, sse2a,sse3, or beyond must be run only on platforms that provide these extensions and features.

Solaris OS releases starting with Solaris 9 4/04 are SSE/SSE2-enabled on Pentium 4-compatible platforms. Earlier versions of Solaris OS are not SSE/SSE2-enabled. If an instruction set selected by -xarch is not enabled in the running Solaris OS, the compiler will not be able to generate or link code for that instruction set.

If you compile and link in separate steps, always link using the compiler and with same -xarch setting to ensure that the correct startup routine is linked.

Numerical results on x86 might differ from results on SPARC due to the x86 80-bit floating-point registers. To minimize these differences, use the -fstore option or compile with -xarch=sse2 if the hardware supports SSE2.

Numerical results can also differ between Solaris and Linux because the intrinsic math libraries (for example, sin(x)) are not the same.

1.3 Binary Compatibility Verification

On Solaris systems, beginning with Sun Studio 11, program binaries compiled with the Sun Studio compilers are marked with architecture hardware flags indicating the instruction sets assumed by the compiled binary. At runtime these marker flags are checked to verify that the binary can run on the hardware it is attempting to execute on.

Running programs that do not contain these architecture hardware flags on platforms that are not enabled with the appropriate features or instruction set extensions could result in segmentation faults or incorrect results occurring without any explicit warning messages.

This warning extends also to programs that employ .il inline assembly language functions or __asm() assembler code that utilize SSE, SSE2, SSE2a, and SSE3 and newer instructions and extensions.

1.4 Compiling for 64–Bit Platforms

Use the —m32 option to compile for the ILP32 32–bit model. Use the —m64 option to compile for the LP64 64–bit model.

The ILP32 model specifies that C-language int, long, and pointer data types are all 32-bits wide. The LP64 model specifies that long and pointer data types are all 64-bits wide. The Solaris and Linux OS also support large files and large arrays under the LP64 memory model.

When you compile with —m64, the resulting executable works only on 64-bit UltraSPARC(R) or x86 processors under Solaris OS or Linux OS running a 64-bit kernel. Compilation, linking, and execution of 64-bit objects can only take place in a Solaris or Linux OS that supports 64-bit execution.

1.5 Standards Conformance

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

This compiler is in full compliance with the C99 standard on Solaris platforms when you specify -xc99=all,lib—Xc.

This compiler also conforms with the ISO/IEC 9899:1990, Programming Languages- C 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.

For information on C90 implementation-specific behavior, see D.1.17 _Pragma.

For more information on C99 features, see Table C–6.

1.6 C Readme File

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

The C compiler readme for this and previous Sun Studio releases can be found on the Sun Developer Network Sun Studio portal, http://developers.sun.com/sunstudio/documentation .

1.7 Man Pages

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

You can display the man page for the C compiler by running the command:


example% man cc

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

Table A–15 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.

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 

-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 

(x86) 

ube

Code generator 

(x86) 

ld

Linker 

 

mcs

Manipulate comment section 

-mr

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