C User's Guide
Sun
Studio 9
817-6697-10
Figures
Tables
Before You Begin
Typographic Conventions
Shell Prompts
Accessing Sun Studio Software and Man Pages
Accessing Compilers and Tools 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
1.1.1 Improved Performance
1.1.2 Improved Optimization
1.1.3 Expanded C99 Compliance
1.1.4 Expanded Support for the Intel Architecture
1.1.5 Support for New SPARC Chips
1.1.6 New Security Checks
1.2 Standards Conformance
1.3 C Readme File
1.4 Man Pages
1.5 Organization of the Compiler
1.6 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 does_not_read_global_data
2.8.3 does_not_return
2.8.4 does_not_write_global_data
2.8.5 error_messages
2.8.6 fini
2.8.7 hdrstop
2.8.8 ident
2.8.9 init
2.8.10 inline
2.8.11 int_to_unsigned
2.8.12 MP serial_loop
2.8.13 MP serial_loop_nested
2.8.14 MP taskloop
2.8.15 nomemorydepend
2.8.16 no_side_effect
2.8.17 opt
2.8.18 pack
2.8.19 pipeloop
2.8.20 rarely_called
2.8.21 redefine_extname
2.8.22 returns_new_memory
2.8.23 unknown_control_flow
2.8.24 unroll
2.8.25 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. Incremental Link Editor (ild)
4.1 Introduction
4.2 Overview of Incremental Linking
4.3 How to Use ild
4.4 How ild Works
4.5 What ild Cannot Do
4.6 Reasons for Full Relinks
4.6.1 ild Deferred-Link Messages
4.6.2 ild Relink Messages
4.6.3 Example 1: Internal Free Space Exhausted
4.6.4 Example 2: Running strip
4.6.5 Example 3: ild Version
4.6.6 Example 4: Too Many Files Changed
4.6.7 Example 5: Full Relink
4.6.8 Example 6: New Working Directory
4.7 ild Options
4.7.1 -a
4.7.2 -B dynamic | static
4.7.3 -d y|n
4.7.4 -e epsym
4.7.5 -g
4.7.6 -I name
4.7.7 -i
4.7.8 -Lpath
4.7.9 -lx
4.7.10 -m
4.7.11 -o outfile
4.7.12 -Q y|n
4.7.13 -Rpath
4.7.14 -s
4.7.15 -t
4.7.16 -u symname
4.7.17 -V
4.7.18 -xildoff
4.7.19 -xildon
4.7.20 -YP,dirlist
4.7.21 -z allextract|defaultextract| weakextract
4.7.22 -z defs
4.7.23 -z i_dryrun
4.7.24 -z i_full
4.7.25 -z i_noincr
4.7.26 -z i_quiet
4.7.27 -z i_verbose
4.7.28 -z nodefs
4.8 Options Passed to ild From the Compilation System
4.8.1 -a
4.8.2 -e epsym
4.8.3 -I name
4.8.4 -m
4.8.5 -t
4.8.6 -u symname
4.8.7 Environment
4.9 ld Options not Supported by ild
4.9.1 -B symbolic
4.9.2 -b
4.9.3 -G
4.9.4 -h name
4.9.5 -z muldefs
4.9.6 -z text
4.10 Additional Unsupported Commands
4.10.1 -D token,token, ...
4.10.2 -F name
4.10.3 -M mapfile
4.10.4 -r
4.11 Files That ild Uses
5. lint Source Code Checker
5.1 Basic and Enhanced lint Modes
5.2 Using lint
5.3 The lint Options
5.3.1 -#
5.3.2 -###
5.3.3 -a
5.3.4 -b
5.3.5 -C filename
5.3.6 -c
5.3.7 -dirout=dir
5.3.8 -err=warn
5.3.9 -errchk=l(, l)
5.3.10 -errfmt=f
5.3.11 -errhdr=h
5.3.12 -erroff=tag(, tag)
5.3.13 -errsecurity=v
5.3.14 -errtags=a
5.3.15 -errwarn=t
5.3.16 -F
5.3.17 -fd
5.3.18 -flagsrc=file
5.3.19 -h
5.3.20 -Idir
5.3.21 -k
5.3.22 -Ldir
5.3.23 -lx
5.3.24 -m
5.3.25 -Ncheck=c
5.3.26 -Nlevel=n
5.3.27 -n
5.3.28 -ox
5.3.29 -p
5.3.30 -Rfile
5.3.31 -s
5.3.32 -u
5.3.33 -V
5.3.34 -v
5.3.35 -Wfile
5.3.36 -XCC=a
5.3.37 -Xalias_level[=l]
5.3.38 -Xarch=v9
5.3.39 -Xc99[=o]
5.3.40 -Xexplicitpar=a
5.3.41 -Xkeeptmp=a
5.3.42 -Xtemp=dir
5.3.43 -Xtime=a
5.3.44 -Xtransition=a
5.3.45 -Xustr={ascii_utf16_ushort|no}
5.3.46 -x
5.3.47 -y
5.4 lint Messages
5.4.1 Options to Suppress Messages
5.4.2 lint Message Formats
5.5 lint Directives
5.5.1 Predefined Values
5.5.2 Directives
5.6 lint Reference and Examples
5.6.1 Diagnostics Performed by lint
5.6.2 lint Libraries
5.6.3 lint Filters
6. Type-Based Alias Analysis
6.1 Introduction to Type-Based Analysis
6.2 Using Pragmas for Finer Control
6.3 Checking With lint
6.3.1 Struct Pointer Cast of Scalar Pointer
6.3.2 Struct Pointer Cast of Void Pointer
6.3.3 Cast of Struct Field to Structure Pointer
6.3.4 Explicit Aliasing Required
6.4 Examples of Memory Reference Constraints
7. Transitioning to ISO C
7.1 Basic Modes
7.1.1 -Xa
7.1.2 -Xc
7.1.3 -Xs
7.1.4 -Xt
7.2 A Mixture of Old- and New-Style Functions
7.2.1 Writing New Code
7.2.2 Updating Existing Code
7.2.3 Mixing Considerations
7.3 Functions With Varying Arguments
7.4 Promotions: Unsigned Versus Value Preserving
7.4.1 Background
7.4.2 Compilation Behavior
7.4.3 First Example: The Use of a Cast
7.4.4 Bit-fields
7.4.5 Second Example: Same Result
7.4.6 Integral Constants
7.4.7 Third Example: Integral Constants
7.5 Tokenization and Preprocessing
7.5.1 ISO C Translation Phases
7.5.2 Old C Translation Phases
7.5.3 Logical Source Lines
7.5.4 Macro Replacement
7.5.5 Using Strings
7.5.6 Token Pasting
7.6 const and volatile
7.6.1 Types, Only for lvalue
7.6.2 Type Qualifiers in Derived Types
7.6.3 const Means readonly
7.6.4 Examples of const Usage
7.6.5 volatile Means Exact Semantics
7.6.6 Examples of volatile Usage
7.7 Multibyte Characters and Wide Characters
7.7.1 Asian Languages Require Multibyte Characters
7.7.2 Encoding Variations
7.7.3 Wide Characters
7.7.4 Conversion Functions
7.7.5 C Language Features
7.8 Standard Headers and Reserved Names
7.8.1 Standard Headers
7.8.2 Names Reserved for Implementation Use
7.8.3 Names Reserved for Expansion
7.8.4 Names Safe to Use
7.9 Internationalization
7.9.1 Locales
7.9.2 The setlocale() Function
7.9.3 Changed Functions
7.9.4 New Functions
7.10 Grouping and Evaluation in Expressions
7.10.1 Definitions
7.10.2 The K&R C Rearrangement License
7.10.3 The ISO C Rules
7.10.4 The Parentheses
7.10.5 The As If Rule
7.11 Incomplete Types
7.11.1 Types
7.11.2 Completing Incomplete Types
7.11.3 Declarations
7.11.4 Expressions
7.11.5 Justification
7.11.6 Examples
7.12 Compatible and Composite Types
7.12.1 Multiple Declarations
7.12.2 Separate Compilation Compatibility
7.12.3 Single Compilation Compatibility
7.12.4 Compatible Pointer Types
7.12.5 Compatible Array Types
7.12.6 Compatible Function Types
7.12.7 Special Cases
7.12.8 Composite Types
8. Converting Applications for a 64-Bit Environment
8.1 Overview of the Data Model Differences
8.2 Implementing Single Source Code
8.2.1 Derived Types
8.2.2 Tools
8.3 Converting to the LP64 Data Type Model
8.3.1 Integer and Pointer Size Change
8.3.2 Integer and Long Size Change
8.3.3 Sign Extension
8.3.4 Pointer Arithmetic Instead of Integers
8.3.5 Structures
8.3.6 Unions
8.3.7 Type Constants
8.3.8 Beware of Implicit Declarations
8.3.9 sizeof( ) Is an Unsigned long
8.3.10 Use Casts to Show Your Intentions
8.3.11 Check Format String Conversion Operation
8.4 Other Considerations
8.4.1 Derived Types That Have Grown in Size
8.4.2 Check for Side Effects of Changes
8.4.3 Check Whether Literal Uses of long Still Make Sense
8.4.4 Use #ifdef for Explicit 32-bit Versus 64-bit Prototypes
8.4.5 Calling Convention Changes
8.4.6 Algorithm Changes
8.5 Checklist for Getting Started
9. cscope: Interactively Examining a C Program
9.1 The cscope Process
9.2 Basic Use
9.2.1 Step 1: Set Up the Environment
9.2.2 Step 2: Invoke the cscope Program
9.2.3 Step 3: Locate the Code
9.2.4 Step 4: Edit the Code
9.2.5 Command-Line Options
9.2.6 View Paths
9.2.7 cscope and Editor Call Stacks
9.2.8 Examples
9.2.9 Command-Line Syntax for Editors
9.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 Option
A.1.7 Compiled-Code Options
A.1.8 Compilation-Mode Options
A.1.9 Diagnostic Option
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 -xbuiltin[=(%all|%none)]
B.2.69 -xCC
B.2.70 -xc99[=o]
B.2.71 -xcache[=c]
B.2.72 -xcg[89|92]
B.2.73 -xchar[=o]
B.2.74 -xchar_byte_order[=o]
B.2.75 -xcheck[=o]
B.2.76 -xchip[=c]
B.2.77 -xcode[=v]
B.2.78 -xcrossfile[=n]
B.2.79 -xcsi
B.2.80 -xdebugformat=[stabs|dwarf]
B.2.81 -xdepend=[yes|no]
B.2.82 -xdryrun
B.2.83 -xe
B.2.84 -xexplicitpar
B.2.85 -xF
B.2.86 -xhelp=f
B.2.87 -xhwcprof
B.2.88 -xildoff
B.2.89 -xildon
B.2.90 -xinline=list
B.2.91 -xipo[=a]
B.2.92 -xipo_archive=[a]
B.2.93 -xjobs=n
B.2.94 -xldscope={v}
B.2.95 -xlibmieee
B.2.96 -xlibmil
B.2.97 -xlibmopt
B.2.98 -xlic_lib=sunperf
B.2.99 -xlicinfo
B.2.100 -xlinkopt[=level]
B.2.101 -xloopinfo
B.2.102 -xM
B.2.103 -xM1
B.2.104 -xMerge
B.2.105 -xmaxopt[=v]
B.2.106 -xmemalign=ab
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[={yes|no}]
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 J.3 Implementation-defined Behavior
C.1.1 J.3.1 Translation
C.1.2 J.3.2 Environment
C.1.3 J.3.3 Identifiers
C.1.4 J.3.4 Characters
C.1.5 J.3.5 Integers
C.1.6 J.3.6 Floating point
C.1.7 J.3.7 Arrays and Pointers
C.1.8 J.3.8 Hints
C.1.9 J.3.9 Structures, Unions, Enumerations, and Bit-fields
C.1.10 J.3.10 Qualifiers
C.1.11 J.3.11 Preprocessing Directives
C.1.12 J.3.12 Library Functions
C.1.13 J.3.13 Architecture
C.1.14 J.4 Locale-specific Behavior
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
I. Implementation-Specific Information of OpenMP
Index
C User's Guide
|
817-6697-10
|
![Table Of Contents Table Of Contents](shared/toc01.gif) ![Previous Chapter Previous Chapter](shared/prev01.gif) ![Next Chapter Next Chapter](shared/next01.gif) ![Book Index Book Index](shared/index01.gif) |
Copyright © 2004, Sun Microsystems, Inc. All rights reserved.