Sun Logo


C User's Guide

Suntrademark Studio 11

819-3688-10



Contents

Figures

Tables

Before You Begin

Typographic Conventions

Shell Prompts

Supported Platforms

Accessing Sun Studio Software and Man Pages

Accessing Sun Studio Documentation

Accessing Related Solaris Documentation

Resources for Developers

Contacting Sun Technical Support

Sending Your Comments

1. Introduction to the C Compiler

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

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

1.3 Standards Conformance

1.4 C Readme File

1.5 Man Pages

1.6 Organization of the Compiler

1.7 C-Related Programming Tools

2. C-Compiler Information Specific to Sun's Implementation

2.1 Constants

2.1.1 Integral Constants

2.1.2 Character Constants

2.2 Linker Scoping Specifiers

2.3 Thread Local Storage Specifier

2.4 Floating Point, Nonstandard Mode

2.5 Labels as Values

2.6 long long Data Type

2.6.1 Printing long long Data Types

2.6.2 Usual Arithmetic Conversions

2.7 Assertions

2.8 Pragmas

2.8.1 align

2.8.2 c99

2.8.3 does_not_read_global_data

2.8.4 does_not_return

2.8.5 does_not_write_global_data

2.8.6 error_messages

2.8.7 fini

2.8.8 hdrstop

2.8.9 ident

2.8.10 init

2.8.11 inline

2.8.12 int_to_unsigned

2.8.13 MP serial_loop

2.8.14 MP serial_loop_nested

2.8.15 MP taskloop

2.8.16 nomemorydepend

2.8.17 no_side_effect

2.8.18 opt

2.8.19 pack

2.8.20 pipeloop

2.8.21 rarely_called

2.8.22 redefine_extname

2.8.23 returns_new_memory

2.8.24 unknown_control_flow

2.8.25 unroll

2.8.26 warn_missing_parameter_info

2.8.27 weak

2.9 Predefined Names

2.10 The Value of errno

2.11 _Restrict Keyword

2.12 _ _asm Keyword

2.13 Environment Variables

2.13.1 OMP_DYNAMIC

2.13.2 OMP_NESTED

2.13.3 OMP_NUM_THREADS

2.13.4 OMP_SCHEDULE

2.13.5 PARALLEL

2.13.6 SUN_PROFDATA

2.13.7 SUN_PROFDATA_DIR

2.13.8 SUNPRO_SB_INIT_FILE_NAME

2.13.9 SUNW_MP_THR_IDLE

2.13.10 TMPDIR

2.14 How to Specify Include Files

2.14.1 Using the -I- Option to Change the Search Algorithm

3. Parallelizing Sun C Code

3.1 Overview

3.1.1 Example of Use

3.2 Parallelizing for OpenMP

3.2.1 Handling OpenMP Runtime Warnings

3.3 Environment Variables

3.4 Data Dependence and Interference

3.4.1 Parallel Execution Model

3.4.2 Private Scalars and Private Arrays

3.4.3 Storeback

3.4.4 Reduction Variables

3.5 Speedups

3.5.1 Amdahl's Law

3.6 Load Balance and Loop Scheduling

3.6.1 Static or Chunk Scheduling

3.6.2 Self Scheduling

3.6.3 Guided Self Scheduling

3.7 Loop Transformations

3.7.1 Loop Distribution

3.7.2 Loop Fusion

3.7.3 Loop Interchange

3.8 Aliasing and Parallelization

3.8.1 Array and Pointer References

3.8.2 Restricted Pointers

3.8.3 Explicit Parallelization and Pragmas

4. lint Source Code Checker

4.1 Basic and Enhanced lint Modes

4.2 Using lint

4.3 The lint Options

4.3.1 -#

4.3.2 -###

4.3.3 -a

4.3.4 -b

4.3.5 -C filename

4.3.6 -c

4.3.7 -dirout=dir

4.3.8 -err=warn

4.3.9 -errchk=l(, l)

4.3.10 -errfmt=f

4.3.11 -errhdr=h

4.3.12 -erroff=tag(, tag)

4.3.13 -errsecurity=v

4.3.14 -errtags=a

4.3.15 -errwarn=t

4.3.16 -F

4.3.17 -fd

4.3.18 -flagsrc=file

4.3.19 -h

4.3.20 -Idir

4.3.21 -k

4.3.22 -Ldir

4.3.23 -lx

4.3.24 -m

4.3.25 -Ncheck=c

4.3.26 -Nlevel=n

4.3.27 -n

4.3.28 -ox

4.3.29 -p

4.3.30 -Rfile

4.3.31 -s

4.3.32 -u

4.3.33 -V

4.3.34 -v

4.3.35 -Wfile

4.3.36 -XCC=a

4.3.37 -Xalias_level[=l]

4.3.38 -Xarch=amd64

4.3.39 -Xarch=v9

4.3.40 -Xc99[=o]

4.3.41 -Xexplicitpar=a

4.3.42 -Xkeeptmp=a

4.3.43 -Xtemp=dir

4.3.44 -Xtime=a

4.3.45 -Xtransition=a

4.3.46 -Xustr={ascii_utf16_ushort|no}

4.3.47 -x

4.3.48 -y

4.4 lint Messages

4.4.1 Options to Suppress Messages

4.4.2 lint Message Formats

4.5 lint Directives

4.5.1 Predefined Values

4.5.2 Directives

4.6 lint Reference and Examples

4.6.1 Diagnostics Performed by lint

4.6.2 lint Libraries

4.6.3 lint Filters

5. Type-Based Alias Analysis

5.1 Introduction to Type-Based Analysis

5.2 Using Pragmas for Finer Control

5.3 Checking With lint

5.3.1 Struct Pointer Cast of Scalar Pointer

5.3.2 Struct Pointer Cast of Void Pointer

5.3.3 Cast of Struct Field to Structure Pointer

5.3.4 Explicit Aliasing Required

5.4 Examples of Memory Reference Constraints

6. Transitioning to ISO C

6.1 Basic Modes

6.1.1 -Xc

6.1.2 -Xa

6.1.3 -Xt

6.1.4 -Xs

6.2 A Mixture of Old- and New-Style Functions

6.2.1 Writing New Code

6.2.2 Updating Existing Code

6.2.3 Mixing Considerations

6.3 Functions With Varying Arguments

6.4 Promotions: Unsigned Versus Value Preserving

6.4.1 Background

6.4.2 Compilation Behavior

6.4.3 First Example: The Use of a Cast

6.4.4 Bit-fields

6.4.5 Second Example: Same Result

6.4.6 Integral Constants

6.4.7 Third Example: Integral Constants

6.5 Tokenization and Preprocessing

6.5.1 ISO C Translation Phases

6.5.2 Old C Translation Phases

6.5.3 Logical Source Lines

6.5.4 Macro Replacement

6.5.5 Using Strings

6.5.6 Token Pasting

6.6 const and volatile

6.6.1 Types, Only for lvalue

6.6.2 Type Qualifiers in Derived Types

6.6.3 const Means readonly

6.6.4 Examples of const Usage

6.6.5 volatile Means Exact Semantics

6.6.6 Examples of volatile Usage

6.7 Multibyte Characters and Wide Characters

6.7.1 Asian Languages Require Multibyte Characters

6.7.2 Encoding Variations

6.7.3 Wide Characters

6.7.4 Conversion Functions

6.7.5 C Language Features

6.8 Standard Headers and Reserved Names

6.8.1 Standard Headers

6.8.2 Names Reserved for Implementation Use

6.8.3 Names Reserved for Expansion

6.8.4 Names Safe to Use

6.9 Internationalization

6.9.1 Locales

6.9.2 The setlocale() Function

6.9.3 Changed Functions

6.9.4 New Functions

6.10 Grouping and Evaluation in Expressions

6.10.1 Definitions

6.10.2 The K&R C Rearrangement License

6.10.3 The ISO C Rules

6.10.4 The Parentheses

6.10.5 The As If Rule

6.11 Incomplete Types

6.11.1 Types

6.11.2 Completing Incomplete Types

6.11.3 Declarations

6.11.4 Expressions

6.11.5 Justification

6.11.6 Examples

6.12 Compatible and Composite Types

6.12.1 Multiple Declarations

6.12.2 Separate Compilation Compatibility

6.12.3 Single Compilation Compatibility

6.12.4 Compatible Pointer Types

6.12.5 Compatible Array Types

6.12.6 Compatible Function Types

6.12.7 Special Cases

6.12.8 Composite Types

7. Converting Applications for a 64-Bit Environment

7.1 Overview of the Data Model Differences

7.2 Implementing Single Source Code

7.2.1 Derived Types

7.2.2 Tools

7.3 Converting to the LP64 Data Type Model

7.3.1 Integer and Pointer Size Change

7.3.2 Integer and Long Size Change

7.3.3 Sign Extension

7.3.4 Pointer Arithmetic Instead of Integers

7.3.5 Structures

7.3.6 Unions

7.3.7 Type Constants

7.3.8 Beware of Implicit Declarations

7.3.9 sizeof( ) Is an Unsigned long

7.3.10 Use Casts to Show Your Intentions

7.3.11 Check Format String Conversion Operation

7.4 Other Considerations

7.4.1 Derived Types That Have Grown in Size

7.4.2 Check for Side Effects of Changes

7.4.3 Check Whether Literal Uses of long Still Make Sense

7.4.4 Use #ifdef for Explicit 32-bit Versus 64-bit Prototypes

7.4.5 Calling Convention Changes

7.4.6 Algorithm Changes

7.5 Checklist for Getting Started

8. cscope: Interactively Examining a C Program

8.1 The cscope Process

8.2 Basic Use

8.2.1 Step 1: Set Up the Environment

8.2.2 Step 2: Invoke the cscope Program

8.2.3 Step 3: Locate the Code

8.2.4 Step 4: Edit the Code

8.2.5 Command-Line Options

8.2.6 View Paths

8.2.7 cscope and Editor Call Stacks

8.2.8 Examples

8.2.9 Command-Line Syntax for Editors

8.3 Unknown Terminal Type Error

A. Compiler Options Grouped by Functionality

A.1 Options Summarized by Function

A.1.1 Optimization and Performance Options

A.1.2 Compile-Time and Link-Time Options

A.1.3 Data-Alignment Options

A.1.4 Numerics and Floating Point Options

A.1.5 Parallelization Options

A.1.6 Source-Code Options

A.1.7 Compiled-Code Options

A.1.8 Compilation-Mode Options

A.1.9 Diagnostic Options

A.1.10 Debugging Options

A.1.11 Linking and Libraries Options

A.1.12 Target-Platform Options

A.1.13 x86-Specific Options

A.1.14 Licensing Options

A.1.15 Obsolete Options

B. C Compiler Options Reference

B.1 Option Syntax

B.2 The cc Options

B.2.1 -#

B.2.2 -###

B.2.3 -Aname[(tokens)]

B.2.4 -B[static|dynamic]

B.2.5 -C

B.2.6 -c

B.2.7 -Dname[=tokens]

B.2.8 -d[y|n]

B.2.9 -dalign

B.2.10 -E

B.2.11 -errfmt[=[no%]error]

B.2.12 -erroff[=t]

B.2.13 -errshort[=i]

B.2.14 -errtags[=a]

B.2.15 -errwarn[=t]

B.2.16 -fast

B.2.17 -fd

B.2.18 -features=[[no%]extinl|%none]

B.2.19 -flags

B.2.20 -flteval[={any|2}]

B.2.21 -fnonstd

B.2.22 -fns[={no|yes}]

B.2.23 -fprecision=p

B.2.24 -fround=r

B.2.25 -fsimple[=n]

B.2.26 -fsingle

B.2.27 -fstore

B.2.28 -ftrap=t[,t...]

B.2.29 -G

B.2.30 -g

B.2.31 -H

B.2.32 -h name

B.2.33 -I[-|dir]

B.2.34 -i

B.2.35 -KPIC

B.2.36 -Kpic

B.2.37 -keeptmp

B.2.38 -Ldir

B.2.39 -lname

B.2.40 -mc

B.2.41 -misalign

B.2.42 -misalign2

B.2.43 -mr[,string]

B.2.44 -mt

B.2.45 -native

B.2.46 -nofstore

B.2.47 -O

B.2.48 -o filename

B.2.49 -P

B.2.50 -p

B.2.51 -Q[y|n]

B.2.52 -qp

B.2.53 -Rdir[:dir]

B.2.54 -S

B.2.55 -s

B.2.56 -Uname

B.2.57 -V

B.2.58 -v

B.2.59 -Wc,arg

B.2.60 -w

B.2.61 -X[c|a|t|s]

B.2.62 -x386

B.2.63 -x486

B.2.64 -xa

B.2.65 -xalias_level[=l]

B.2.66 -xarch=isa

B.2.67 -xautopar

B.2.68 -xbinopt={prepare|off}

B.2.69 -xbuiltin[=(%all|%none)]

B.2.70 -xCC

B.2.71 -xc99[=o]

B.2.72 -xcache[=c]

B.2.73 -xcg[89|92]

B.2.74 -xchar[=o]

B.2.75 -xchar_byte_order[=o]

B.2.76 -xcheck[=o]

B.2.77 -xchip[=c]

B.2.78 -xcode[=v]

B.2.79 -xcrossfile[=n]

B.2.80 -xcsi

B.2.81 -xdebugformat=[stabs|dwarf]

B.2.82 -xdepend=[yes|no]

B.2.83 -xdryrun

B.2.84 -xe

B.2.85 -xexplicitpar

B.2.86 -xF

B.2.87 -xhelp=f

B.2.88 -xhwcprof

B.2.89 -xinline=list

B.2.90 -xipo[=a]

B.2.91 -xipo_archive=[a]

B.2.92 -xjobs=n

B.2.93 -xldscope={v}

B.2.94 -xlibmieee

B.2.95 -xlibmil

B.2.96 -xlibmopt

B.2.97 -xlic_lib=sunperf

B.2.98 -xlicinfo

B.2.99 -xlinkopt[=level]

B.2.100 -xloopinfo

B.2.101 -xM

B.2.102 -xM1

B.2.103 -xMerge

B.2.104 -xmaxopt[=v]

B.2.105 -xmemalign=ab

B.2.106 -xmodel=[a]

B.2.107 -xnativeconnect[=a[,a]...]

B.2.108 -xnolib

B.2.109 -xnolibmil

B.2.110 -xnolibmopt

B.2.111 -xO[1|2|3|4|5]

B.2.112 -xopenmp[=i]

B.2.113 -xP

B.2.114 -xpagesize=n

B.2.115 -xpagesize_heap=n

B.2.116 -xpagesize_stack=n

B.2.117 -xparallel

B.2.118 -xpch=v

B.2.119 -xpchstop=[file|<include>]

B.2.120 -xpentium

B.2.121 -xpg

B.2.122 -xprefetch[=val[,val]]

B.2.123 -xprefetch_auto_type=a

B.2.124 -xprefetch_level=l

B.2.125 -xprofile=p

B.2.126 -xprofile_ircache[=path]

B.2.127 -xprofile_pathmap

B.2.128 -xreduction

B.2.129 -xregs=r[,r...]

B.2.130 -xrestrict[=f]

B.2.131 -xs

B.2.132 -xsafe=mem

B.2.133 -xsb

B.2.134 -xsbfast

B.2.135 -xsfpconst

B.2.136 -xspace

B.2.137 -xstrconst

B.2.138 -xtarget=t

B.2.139 -xtemp=dir

B.2.140 -xthreadvar[=o]

B.2.141 -xtime

B.2.142 -xtransition

B.2.143 -xtrigraphs

B.2.144 -xunroll=n

B.2.145 -xustr={ascii_utf16_ushort|no}

B.2.146 -xvector[=a]

B.2.147 -xvis

B.2.148 -xvpara

B.2.149 -Yc, dir

B.2.150 -YA, dir

B.2.151 -YI, dir

B.2.152 -YP, dir

B.2.153 -YS, dir

B.2.154 -Zll

B.3 Options Passed to the Linker

C. Implementation-Defined ISO/IEC C99 Behavior

C.1 Implementation-defined Behavior (J.3 )

C.1.1 Translation (J.3.1 )

C.1.2 Environment (J.3.2)

C.1.3 Identifiers (J.3.3)

C.1.4 Characters (J.3.4)

C.1.5 Integers (J.3.5)

C.1.6 Floating point (J.3.6)

C.1.7 Arrays and Pointers (J.3.7)

C.1.8 Hints (J.3.8)

C.1.9 Structures, Unions, Enumerations, and Bit-fields (J.3.9)

C.1.10 Qualifiers (J.3.10)

C.1.11 Preprocessing Directives (J.3.11)

C.1.12 Library Functions (J.3.12)

C.1.13 Architecture (J.3.13)

C.1.14 Locale-specific Behavior (J.4)

D. Supported Features of C99

D.1 Discussion and Examples

D.1.1 Precision of Floating Point Evaluators

D.1.2 C99 Keywords

D.1.3 __func__ Support

D.1.4 Universal Character Names (UCN)

D.1.5 Commenting Code With //

D.1.6 Disallowed Implicit int and Implicit Function Declarations

D.1.7 Declarations Using Implicit int

D.1.8 Flexible Array Members

D.1.9 Idempotent Qualifiers

D.1.10 inline Functions

D.1.11 Static and Other Type Qualifiers Allowed in Array Declarators

D.1.12 Variable Length Arrays (VLA):

D.1.13 Designated Initializers

D.1.14 Mixed Declarations and Code

D.1.15 Declaration in for-Loop Statement

D.1.16 Macros With a Variable Number of Arguments

D.1.17 _Pragma

E. Implementation-Defined ISO/IEC C90 Behavior

E.1 Implementation Compared to the ISO Standard

E.1.1 Translation (G.3.1)

E.1.2 Environment (G.3.2)

E.1.3 Identifiers (G.3.3)

E.1.4 Characters (G.3.4)

E.1.5 Integers (G.3.5)

E.1.6 Floating-Point (G.3.6)

E.1.7 Arrays and Pointers (G.3.7)

E.1.8 Registers (G.3.8)

E.1.9 Structures, Unions, Enumerations, and Bit-Fields (G.3.9)

E.1.10 Qualifiers (G.3.10)

E.1.11 Declarators (G.3.11)

E.1.12 Statements (G.3.12)

E.1.13 Preprocessing Directives (G.3.13)

E.1.14 Library Functions (G.3.14)

E.1.15 Locale-Specific Behavior (G.4)

F. ISO C Data Representations

F.1 Storage Allocation

F.2 Data Representations

F.2.1 Integer Representations

F.2.2 Floating-Point Representations

F.2.3 Exceptional Values

F.2.4 Hexadecimal Representation of Selected Numbers

F.2.5 Pointer Representation

F.2.6 Array Storage

F.2.7 Arithmetic Operations on Exceptional Values

F.3 Argument-Passing Mechanism

G. Performance Tuning (SPARC)

G.1 Limits

G.2 libfast.a Library

H. The Differences Between K&R Sun C and Sun ISO C

H.1 K&R Sun C Incompatibilities With Sun ISO C

H.2 Keywords

Index