ILE C/C++ Language Reference, SC09-7852
Total Page:16
File Type:pdf, Size:1020Kb
IBM IBM i Websphere Development Studio ILE C/C++ Language Reference 7.1 SC09-7852-02 IBM IBM i Websphere Development Studio ILE C/C++ Language Reference 7.1 SC09-7852-02 Note! Before using this information and the product it supports, be sure to read the general information under “Notices” on page 355. This edition applies to IBM i 7.1, (program 5770-WDS), ILE C/C++ compilers, and to all subsequent releases and modifications until otherwise indicated in new editions. This version does not run on all reduced instruction set computer (RISC) models nor does it run on CISC models. © Copyright IBM Corporation 1998, 2010. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents About ILE C/C++ Language Reference Digraph characters ........... 27 (SC09-7852-01) ........... ix Trigraph sequences ........... 28 Who should read this book ......... ix Comments............... 28 Highlighting Conventions .......... x How to Read the Syntax Diagrams ....... x Chapter 3. Data objects and Prerequisite and related information ...... xii declarations ............ 31 How to send your comments ........ xii Overview of data objects and declarations .... 31 Overview of data objects ......... 31 What's new for IBM i 7.1 ....... xv Incomplete types .......... 32 Compatible and composite types ..... 32 Chapter 1. Scope and linkage ..... 1 Overview of data declarations and definitions .. 33 Tentative definitions ......... 34 Scope ................. 1 Storage class specifiers........... 35 Block/local scope ............ 2 The auto storage class specifier ....... 35 Function scope ............ 2 Storage duration of automatic variables ... 35 Function prototype scope ......... 3 Linkage of automatic variables ...... 36 File/global scope ............ 3 The static storage class specifier ...... 36 Examples of scope in C .......... 3 Linkage of static variables ....... 36 Class scope (C++ only) .......... 4 The extern storage class specifier ...... 37 Namespaces of identifiers ......... 5 Storage duration of external variables ... 37 Name hiding (C++ only) ......... 6 Linkage of external variables ...... 37 Program linkage ............. 6 The mutable storage class specifier (C++ only).. 38 Internal linkage ............ 7 The register storage class specifier ...... 38 External linkage ............ 7 Storage duration of register variables .... 39 No linkage .............. 8 Linkage of register variables ....... 39 Language linkage............ 8 The __thread storage class specifier ..... 39 Name mangling (C++ only) ....... 9 Type specifiers ............. 40 Integral types............. 40 Chapter 2. Lexical Elements ..... 11 Boolean types ............ 41 Tokens ................ 11 Floating-point types .......... 41 Keywords .............. 11 Real floating-point types ........ 42 Keywords for language extensions..... 12 Character types ............ 43 Identifiers .............. 12 The void type ............ 43 Characters in identifiers ........ 13 Compatibility of arithmetic types (C only) ... 43 Reserved identifiers ......... 13 User-defined types ............ 44 The __func__ predefined identifier..... 14 Structures and unions .......... 44 Literals ............... 14 Structure and union type definition .... 44 Integer literals ........... 15 Member declarations ......... 45 Decimal integer literals ....... 15 Flexible array members ....... 46 Hexadecimal integer literals ...... 16 Zero-extent array members ...... 47 Octal integer literals ........ 16 Bit field members ......... 47 Boolean literals ........... 16 Structure and union variable declarations .. 49 Floating-point literals ......... 17 Structure and union type and variable Binary floating-point literals ...... 17 definitions in a single statement ..... 50 Hexadecimal floating-point literals ... 18 Access to structure and union members ... 50 Decimal floating-point literals ..... 19 Anonymous unions.......... 51 Packed Decimal Literals ........ 20 Enumerations............. 51 Character literals .......... 20 Enumeration type definition ....... 51 String literals ............ 21 Enumeration members........ 52 String concatenation ........ 22 Enumeration variable declarations ..... 53 Punctuators and operators ........ 23 Enumeration type and variable definitions in a Alternative tokens .......... 23 single statement ........... 53 Source program character set ........ 24 Compatibility of structures, unions, and Multibyte characters .......... 25 enumerations (C only) .......... 54 Escape sequences ........... 26 Compatibility across separate source files .. 54 The Unicode standard .......... 26 © Copyright IBM Corp. 1998, 2010 iii typedef definitions ........... 55 Primary expressions ........... 96 Examples of typedef definitions ..... 55 Names ............... 96 Type qualifiers ............. 56 Literals ............... 97 The __align type qualifier ........ 57 Integer constant expressions ........ 97 Examples using the __align qualifier .... 58 Identifier expressions (C++ only) ...... 98 The const type qualifier ......... 59 Parenthesized expressions ( ) ....... 98 The restrict type qualifier ......... 60 Scope resolution operator :: (C++ only) .... 99 The volatile type qualifier ........ 61 Function call expressions ......... 100 Type attributes ............. 61 Member expressions ........... 101 The aligned type attribute ........ 62 Dot operator . ............ 101 The packed type attribute ........ 63 Arrow operator −> .......... 101 The transparent_union type attribute (C only) .. 63 Unary expressions ............ 101 Increment operator ++ ......... 102 Chapter 4. Declarators ........ 65 Decrement operator −− ......... 102 Overview of declarators .......... 65 Unary plus operator + ......... 103 Examples of declarators ......... 66 Unary minus operator - ......... 103 Type names .............. 67 Logical negation operator ! ........ 103 Pointers ............... 68 Bitwise negation operator ~ ....... 104 Pointer arithmetic ........... 69 Address operator & .......... 104 Type-based aliasing........... 70 Indirection operator *.......... 105 Compatibility of pointers (C only) ...... 71 The typeid operator (C++ only) ...... 105 Arrays ................ 71 The __alignof__ operator ........ 106 Variable length arrays (C++ only) ...... 72 The sizeof operator .......... 107 Compatibility of arrays ......... 73 The __typeof__ operator......... 108 References (C++ only) ........... 74 Binary expressions............ 109 Initializers ............... 74 Assignment operators ......... 110 Initialization and storage classes ...... 75 Simple assignment operator = ...... 110 Initialization of automatic variables .... 75 Compound assignment operators ..... 110 Initialization of static variables ...... 75 Multiplication operator *......... 111 Initialization of external variables ..... 76 Division operator / .......... 112 Initialization of register variables ..... 76 Remainder operator % ......... 112 Initialization of structures and unions .... 76 Addition operator + .......... 112 Initialization of enumerations ....... 78 Subtraction operator − ......... 113 Initialization of pointers ......... 78 Bitwise left and right shift operators << >> .. 113 Initialization of arrays .......... 78 Relational operators < > <= >= ...... 114 Initialization of character arrays ..... 79 Equality and inequality operators == != ... 115 Initialization of multidimensional arrays... 80 Bitwise AND operator & ........ 115 Initialization of references (C++ only)..... 81 Bitwise exclusive OR operator ^ ...... 116 Direct binding ........... 82 Bitwise inclusive OR operator | ...... 116 Variable attributes ............ 82 Logical AND operator && ........ 117 The aligned variable attribute ....... 83 Logical OR operator || ......... 117 The packed variable attribute ....... 84 Array subscripting operator [ ] ...... 118 The mode variable attribute ........ 84 Comma operator , ........... 119 The weak variable attribute ........ 85 Pointer to member operators .* −>* (C++ only) 121 Conditional expressions .......... 121 Chapter 5. Type conversions ..... 87 Types in conditional C expressions ..... 122 Types in conditional C++ expressions .... 122 Arithmetic conversions and promotions ..... 87 Examples of conditional expressions..... 122 Integral conversions .......... 87 Cast expressions ............ 123 Boolean conversions .......... 88 Cast operator ()............ 123 Floating-point conversions ........ 88 The static_cast operator (C++ only) ..... 125 Integral and floating-point promotions .... 89 The reinterpret_cast operator (C++ only) ... 126 Lvalue-to-rvalue conversions ........ 90 The const_cast operator (C++ only) ..... 127 Pointer conversions............ 90 The dynamic_cast operator (C++ only) .... 128 Conversion to void* .......... 91 Compound literal expressions ........ 130 Reference conversions (C++ only) ....... 92 new expressions (C++ only) ........ 130 Qualification conversions (C++ only) ...... 92 Placement syntax ........... 132 Function argument conversions........ 92 Initialization of objects created with the new operator .............. 133 Chapter 6. Expressions and operators 95 Handling new allocation failure ...... 133 Lvalues and rvalues ........... 95 delete expressions (C++ only) ........ 134 iv ILE C/C++ Language Reference throw expressions (C++ only) ........ 135 Allocation and deallocation functions (C++ only) 178 Operator precedence and associativity ..... 135 Default arguments in C++ functions (C++ only) 179 Restrictions on default