C Language Reference



C Language Reference








Table of Contents:





About this document . . . . . . . .vii
Who should read this document . . . . . . .vii
Supported language standards . . . . . . . .vii
Other standards and specifications . . . . .vii
Language levels and language extensions . . . .viii
Extensions related to GNU C . . . . . . .viii
Extensions supporting the AltiVec Programming Interface . . . . . . . . . . . . . .viii
How to use this document . . . . . . . . .ix
How this document is organized . . . . . . .ix
Conventions used in this document . . . . . .ix
Typographical conventions . . . . . . . .ix
Qualifying elements (icons and bracket separators) x
How to read syntax diagrams . . . . . . .x
Examples . . . . . . . . . . . . . .xii
Related information . . . . . . . . . . .xii
IBM XL C publications . . . . . . . . .xii
Additional documentation . . . . . . . .xiii
Related publications . . . . . . . . . .xiii
Technical support . . . . . . . . . . . .xiii
How to send your comments . . . . . . . .xiv

Chapter 1. Scope and linkage . . . . .1
Scope . . . . . . . . . . . . . . . . .1
Block scope . . . . . . . . . . . . . .2
Function scope . . . . . . . . . . . .3
Function prototype scope . . . . . . . . .3
File scope . . . . . . . . . . . . . .3
Examples of scope in C . . . . . . . . . .3
Namespaces of identifiers . . . . . . . . .4
Program linkage . . . . . . . . . . . . .5
Internal linkage . . . . . . . . . . . .5
External linkage . . . . . . . . . . . .6
No linkage . . . . . . . . . . . . . .6

Chapter 2. Lexical Elements . . . . . .7
Tokens . . . . . . . . . . . . . . . .7
Keywords . . . . . . . . . . . . . .7
Identifiers . . . . . . . . . . . . . .8
Literals . . . . . . . . . . . . . . .11
Punctuators and operators . . . . . . . .21
Source program character set . . . . . . . .22
Multibyte characters . . . . . . . . . .22
Escape sequences . . . . . . . . . . .23
The Unicode standard . . . . . . . . . .24
Digraph characters . . . . . . . . . . .26
Trigraph sequences . . . . . . . . . . .26
Comments . . . . . . . . . . . . . . .27

Chapter 3. Data objects and declarations . . . . . . . . . . . .31
Overview of data objects and declarations . . . .31
Overview of data objects . . . . . . . . .31
Overview of data declarations and definitions . .33
Storage class specifiers . . . . . . . . . . .35
The auto storage class specifier . . . . . . .35
The static storage class specifier . . . . . .36
The extern storage class specifier . . . . . .37
The register storage class specifier . . . . . .37
Type specifiers . . . . . . . . . . . . .39
Integral types . . . . . . . . . . . . .39
Boolean types . . . . . . . . . . . .40
Floating-point types . . . . . . . . . .41
Character types . . . . . . . . . . . .41
The void type . . . . . . . . . . . .42
Compatibility of arithmetic types (C only) . . .42
Vector types . . . . . . . . . . . . .43
User-defined types . . . . . . . . . . . .44
Structures and unions . . . . . . . . . .44
Enumerations . . . . . . . . . . . . .51
Compatibility of structures, unions, and enumerations (C only) . . . . . . . . . .53
typedef definitions . . . . . . . . . . .54
Type qualifiers . . . . . . . . . . . . .56
The const type qualifier . . . . . . . . .57
The volatile type qualifier . . . . . . . .57
The restrict type qualifier . . . . . . . . .58
The __align qualifier . . . . . . . . . .59
Type attributes . . . . . . . . . . . . .61
The aligned type attribute . . . . . . . .62
The packed type attribute . . . . . . . .62
The transparent_union type attribute (C only) . .63

Chapter 4. Declarators . . . . . . . .65
Overview of declarators . . . . . . . . . .65
Examples of declarators . . . . . . . . .66
Type names . . . . . . . . . . . . . .66
Pointers . . . . . . . . . . . . . . .68
Pointer arithmetic . . . . . . . . . . .68
Type-based aliasing . . . . . . . . . . .69
Compatibility of pointers (C only) . . . . . .70
Arrays . . . . . . . . . . . . . . . .70
Variable length arrays . . . . . . . . . .72
Compatibility of arrays . . . . . . . . .73
Initializers . . . . . . . . . . . . . . .73
Initialization and storage classes . . . . . .74
Designated initializers for aggregate types (C only) . . . . . . . . . . . . . . .75
Initialization of vectors . . . . . . . . .77
Initialization of structures and unions . . . .78
Initialization of enumerations . . . . . . .80
Initialization of pointers . . . . . . . . .80
Initialization of arrays . . . . . . . . . .81
Variable attributes . . . . . . . . . . . .83
The aligned variable attribute . . . . . . .85
The packed variable attribute . . . . . . .86
The mode variable attribute . . . . . . . .86
The weak variable attribute . . . . . . . .86

Chapter 5. Type conversions . . . . .89 
Arithmetic conversions and promotions . . . . .89
Integral conversions . . . . . . . . . .89
Boolean conversions . . . . . . . . . .90
Floating-point conversions . . . . . . . .90
Integral and floating-point promotions . . . .91
Lvalue-to-rvalue conversions . . . . . . . .92
Pointer conversions . . . . . . . . . . . .92
Conversion to void* . . . . . . . . . .93
Function argument conversions . . . . . . . .93

Chapter 6. Expressions and operators 95
Lvalues and rvalues . . . . . . . . . . .95
Primary expressions . . . . . . . . . . .97
Names . . . . . . . . . . . . . . .97
Literals . . . . . . . . . . . . . . .97
Integer constant expressions . . . . . . . .98
Parenthesized expressions ( ) . . . . . . .98
Postfix expressions . . . . . . . . . . . .99
Function call operator ( ) . . . . . . . . .99
Array subscripting operator [ ] . . . . . .100
Dot operator . . . . . . . . . . . . .101
Arrow operator −> . . . . . . . . . .101
Compound literals . . . . . . . . . . .102
Unary expressions . . . . . . . . . . . .102
Increment operator ++ . . . . . . . . .103
Decrement operator −− . . . . . . . . .104
Unary plus operator + . . . . . . . . .104
Unary minus operator . . . . . . . . .104
Logical negation operator ! . . . . . . . .105
Bitwise negation operator ~ . . . . . . .105
Address operator & . . . . . . . . . .105
Indirection operator * . . . . . . . . . .106
The __alignof__ operator . . . . . . . .107
The sizeof operator . . . . . . . . . .108
The typeof operator . . . . . . . . . .109
Label value operator && . . . . . . . .110
The _Pragma preprocessing operator . . . .110
The __real__ and __imag__ operators . . . .111
Cast expressions . . . . . . . . . . . .111
Cast to union type (C only) . . . . . . . .112
Binary expressions . . . . . . . . . . . .113
Multiplication operator * . . . . . . . .113
Division operator / . . . . . . . . . .114
Remainder operator % . . . . . . . . .114
Addition operator + . . . . . . . . . .114
Subtraction operator − . . . . . . . . .115
Bitwise left and right shift operators << >> . .115
Relational operators < > <= >= . . . . . .116
Equality and inequality operators == != . . .117
Bitwise AND operator & . . . . . . . .118
Bitwise exclusive OR operator ^ . . . . . .118
Bitwise inclusive OR operator | . . . . . .119
Logical AND operator && . . . . . . . .119
Logical OR operator || . . . . . . . . .120
Conditional expressions . . . . . . . . . .121
Types in conditional C expressions . . . . .121
Examples of conditional expressions . . . . .122
Assignment expressions . . . . . . . . . .123
Simple assignment operator = . . . . . . .123
Compound assignment operators . . . . . .124
Comma expressions . . . . . . . . . . .125
Operator precedence and associativity . . . . .126

Chapter 7. Statements . . . . . . .131
Labeled statements . . . . . . . . . . .131
Locally declared labels . . . . . . . . .132
Labels as values . . . . . . . . . . .132
Expression statements . . . . . . . . . .133
Block statements . . . . . . . . . . . .133
Example of blocks . . . . . . . . . . .133
Statement expressions . . . . . . . . .134
Selection statements . . . . . . . . . . .135
The if statement . . . . . . . . . . .135
The switch statement . . . . . . . . . .136
Iteration statements . . . . . . . . . . .140
The while statement . . . . . . . . . .140
The do statement . . . . . . . . . . .141
The for statement . . . . . . . . . . .142
Jump statements . . . . . . . . . . . .143
The break statement . . . . . . . . . .144
The continue statement . . . . . . . . .144
The return statement . . . . . . . . . .145
The goto statement . . . . . . . . . .147
Null statement . . . . . . . . . . . . .148
Inline assembly statements . . . . . . . . .149
Examples of inline assembly statements . . .150
Restrictions on inline assembly statements . . .151

Chapter 8. Functions . . . . . . . .153
Function declarations and definitions . . . . .153
Function declarations . . . . . . . . . .153
Function definitions . . . . . . . . . .154
Examples of function declarations . . . . .155
Examples of function definitions . . . . . .155
Compatible functions . . . . . . . . . .156
Function storage class specifiers . . . . . . .156
The static storage class specifier . . . . . .156
The extern storage class specifier . . . . . .156
Function specifiers . . . . . . . . . . .157
The inline function specifier . . . . . . .157
Function return type specifiers . . . . . . .159
Function return values . . . . . . . . .159
Function declarators . . . . . . . . . . .160
Parameter declarations . . . . . . . . .160
Function attributes . . . . . . . . . . .162
The alias function attribute . . . . . . . .163
The always_inline function attribute . . . . .163
The const function attribute . . . . . . .164
The format function attribute . . . . . . .164
The format_arg function attribute . . . . .165
The noinline function attribute . . . . . .165
The noreturn function attribute . . . . . .166
The pure function attribute . . . . . . . .166
The weak function attribute . . . . . . .166
The main() function . . . . . . . . . . .167
Function calls . . . . . . . . . . . . .168
Pass by value . . . . . . . . . . . .168
Pass by reference . . . . . . . . . . .169
Pointers to functions . . . . . . . . . . .169
Nested functions . . . . . . . . . . . .170 iv XL C Language Reference

Chapter 9. Preprocessor Directives 171
Macro definition directives . . . . . . . . .171
The #define directive . . . . . . . . . .172
The #undef directive . . . . . . . . . .176
The # operator . . . . . . . . . . . .177
The ## operator . . . . . . . . . . .178
Standard predefined macro names . . . . .178
File inclusion directives . . . . . . . . . .179
The #include directive . . . . . . . . .180
The #include_next directive . . . . . . . .181
Conditional compilation directives . . . . . .181
The #if and #elif directives . . . . . . . .182
The #ifdef directive . . . . . . . . . .183
The #ifndef directive . . . . . . . . . .183
The #else directive . . . . . . . . . . .184
The #endif directive . . . . . . . . . .184
Message generation directives . . . . . . . .185
The #error directive . . . . . . . . . .185
The #warning directive . . . . . . . . .186
The #line directive . . . . . . . . . . .186
Assertion directives . . . . . . . . . . .187
Predefined assertions . . . . . . . . . .188
The null directive (#) . . . . . . . . . . .188
Pragma directives . . . . . . . . . . . .188
Standard pragmas . . . . . . . . . . .189
Appendix A. The IBM XL C language extensions . . . . . . . . . . . .191
C99 features as extensions to C89 . . . . . . .191
Extensions for Unicode support . . . . . . .193
Extensions for GNU C compatibility . . . . . .193
Extensions for VMX support . . . . . . . .195
Appendix B. Vector data types and literals . . . . . . . . . . . . . .197
Index . . . . . . . . . . . . . . .199
Notices . . . . . . . . . . . . . .205
Programming interface information . . . . . .206
Trademarks and service marks . . . . . . .207
Industry standards . . . . . . . . . . .207
Contents







Click here for  Download PDF / FREE

C Language Reference




0 commentaires: