# HG changeset patch # User roug # Date 1049147238 0 # Node ID c8fcb9426d8b3bbfc2e9e8a5bb31e6c37528b9ae # Parent 9f274edaf94f06dd315a55ad6d3eae436f422b73 Crossreferences to Reference appendix diff -r 9f274edaf94f -r c8fcb9426d8b docs/ccguide/creference.appendix --- a/docs/ccguide/creference.appendix Mon Mar 31 19:21:49 2003 +0000 +++ b/docs/ccguide/creference.appendix Mon Mar 31 21:47:18 2003 +0000 @@ -1,6 +1,6 @@ C Reference Manual -Introduction +Introduction This manual describes the C language on the DEC PDP-11 DEC PDP-11, and DEC VAX-11 are trademarks of Digital Equipment Corporation. @@ -13,7 +13,7 @@ follow directly from the underlying properties of the hardware; the various compilers are generally quite compatible. -Lexical Conventions +Lexical Conventions There are six classes of tokens - identifiers, keywords, constants, strings, operators, and other separators. @@ -30,18 +30,16 @@ to include the longest string of characters which could possibly constitute a token. -Comments +Comments The characters - -/* - +/* introduce a comment which terminates with the characters */. Comments do not nest. -Identifiers (Names) +Identifiers (Names) An identifier is a sequence of letters and digits. The first character must be a letter. @@ -76,53 +74,61 @@ -Keywords +Keywords The following identifiers are reserved for use as keywords and may not be used otherwise: - + - auto - do - for - return - typedef - - - break - double - goto - short - union - - - case + int + extern else - if - sizeof - unsigned char - enum - int - static - direct + register + for - continue - external - long - struct + float + typedef + do + + + double + static while + struct + goto + switch + + + union + return + case + + + long + sizeof default - float + + + short + break + entry + + + unsigned + continue register - switch + + + auto + if @@ -130,26 +136,25 @@ Some implementations also reserve the words +direct fortran and asm -Constants +Constants There are several kinds of constants. -Each has a type; an introduction to types is given in NAMES. +Each has a type; an introduction to types is given in . Hardware characteristics that affect sizes are summarized in -Hardware Characteristics under LEXICAL CONVENTIONS. +Hardware Characteristics under . -Integer Constants +Integer Constants An integer constant consisting of a sequence of digits is taken to be octal if it begins with - -0 - +0 (digit zero). An octal constant consists of the digits 0 through 7 only. A sequence of digits preceded by @@ -158,9 +163,7 @@ 0X (digit zero) is taken to be a hexadecimal integer. The hexadecimal digits include - -a - +a or A through @@ -176,24 +179,19 @@ is likewise taken to be long. -Explicit Long Constants +Explicit Long Constants A decimal, octal, or hexadecimal integer constant immediately followed by - -l - -(letter ell) -or - -L - +l +(letter ell) or +L is a long constant. As discussed below, on some machines integer and long values may be considered identical. -Character Constants +Character Constants A character constant is a character enclosed in single quotes, as in 'x'. @@ -262,33 +260,27 @@ -The escape -\ddd +The escape \ddd consists of the backslash followed by 1, 2, or 3 octal digits which are taken to specify the value of the desired character. A special case of this construction is - -\0 - +\0 (not followed by a digit), which indicates the character - -NUL. +NUL. If the character following a backslash is not one of those specified, the behavior is undefined. A new-line character is illegal in a character constant. The type of a character constant is int. -Floating Constants +Floating Constants A floating constant consists of an integer part, a decimal point, a fraction part, an - -e - +e or E, and an optionally signed integer exponent. @@ -298,20 +290,11 @@ part (not both) may be missing. Either the decimal point or the - -e - +e and the exponent (not both) may be missing. -Every floating constant has type double. - -Enumeration Constants - -Names declared as enumerators -(see Structure, Union, and Enumeration Declarations under -DECLARATIONS) -have type int. +Every floating constant is taken to be double-precision. -Strings +Strings A string is a sequence of characters surrounded by double quotes, @@ -320,11 +303,9 @@ A string has type array of char and storage class static -(see NAMES) -and is initialized with -the given characters. -The compiler places -a null byte +(see ) +and is initialized with the given characters. +The compiler places a null byte (\0) at the end of each string so that programs which scan the string can @@ -338,24 +319,22 @@ constants may be used. A - -\ - +\ and the immediately following newline are ignored. All strings, even when written identically, are distinct. -Hardware Characteristics +Hardware Characteristics The following figure summarize certain hardware properties that vary from machine to machine. -DEC PDP-11 HARDWARE CHARACTERISTICS +DEC PDP-11 Hardware Characteristics - DEC PDP\-11 + DEC PDP-11 DEC VAX-11 6809 @@ -420,9 +399,9 @@
- -Syntax Notation - + +Syntax Notation + Syntactic categories are indicated by italic @@ -440,11 +419,11 @@ indicates an optional expression enclosed in braces. -The syntax is summarized in SYNTAX SUMMARY. +The syntax is summarized in . - -What's in a name? - + +What's in a name? + C bases the interpretation of an identifier upon two attributes of the identifier: its storage class @@ -460,8 +439,8 @@ There are four declarable storage classes: automatic, static, external, and register. Automatic variables are local to each invocation of -a block (see Compound Statement or Block in -STATEMENTS) and are discarded upon exit from the block. +a block (see ) +and are discarded upon exit from the block. Static variables are local to a block but retain their values upon reentry to a block even after control has left the block. @@ -500,15 +479,12 @@ by the host machine architecture. The other sizes are provided to meet special needs. -Unsigned -integers, declared +Unsigned integers, declared unsigned, obey the laws of arithmetic modulo 2n where n is the number of bits in the representation. -(On the -PDP-11, -unsigned long quantities are not supported.) +(On the PDP-11, unsigned long quantities are not supported.) Single-precision floating point (float) @@ -518,23 +494,16 @@ Because objects of the foregoing types can usefully be interpreted as numbers, they will be referred to as - -arithmetic - +arithmetic types. Types -char, +char and int -of all sizes whether unsigned or not, and - -enum - -will collectively be called +of all sizes will collectively be called integral types. -The float and double @@ -547,78 +516,58 @@ from the fundamental types in the following ways: -Arrays +arrays of objects of most types -Functions +functions which return objects of a given type -Pointers +pointers to objects of a given type -Structures +structures containing a sequence of objects of various types -Unions +unions capable of containing any one of several objects of various types. -In general these methods -of constructing objects can -be applied recursively. +In general these methods of constructing objects can be applied recursively. -Objects and lvalues +Objects and lvalues An - -object - +object is a manipulatable region of storage. -An - -lvalue - +An lvalue is an expression referring to an object. An obvious example of an lvalue expression is an identifier. There are operators which yield lvalues: for example, if - -E - +E is an expression of pointer type, then - -*E - +*E is an lvalue expression referring to the object to which - -E - -points. +E points. The name lvalue comes from the assignment expression - -E1\ =\ E2 - +E1 = E2 in which the left operand - -E1 - +E1 must be an lvalue expression. The discussion of each operator below indicates whether it expects lvalue operands and whether it yields an lvalue. - -Conversions - +Conversions A number of operators may, depending on their operands, cause conversion of the value of an operand from one type to another. This part explains the result to be expected from such @@ -629,7 +578,7 @@ as required by the discussion of each operator. -Characters and Integers +Characters and Integers A character or a short integer may be used wherever an integer may be used. @@ -665,8 +614,7 @@ for example, '\377' has the value - --1. +-1. When a longer integer is converted to a shorter integer @@ -675,7 +623,7 @@ it is truncated on the left. Excess bits are simply discarded. -Float and Double +Float and Double All floating arithmetic in C is carried out in double precision. Whenever a @@ -699,7 +647,7 @@ On the VAX, the compiler can be directed to use single percision for expressions containing only float and interger operands. -Floating and Integral +Floating and Integral Conversions of floating values to integral type are rather machine dependent. @@ -713,7 +661,7 @@ Some loss of accuracy occurs if the destination lacks sufficient bits. -Pointers and Integers +Pointers and Integers An expression of integral type may be added to or subtracted from a pointer; in such a case, @@ -798,19 +746,16 @@ - -Expressions - + +Expressions The precedence of expression operators is the same as the order of the major subsections of this section, highest precedence first. Thus, for example, the expressions referred to as the operands of - -+ - -(see Additive Operators) -are those expressions defined under Primary Expressions, -Unary Operators, and Multiplicative Operators. ++ +(see ) +are those expressions defined under , +, and . Within each subpart, the operators have the same precedence. Left- or right-associativity is specified @@ -818,7 +763,7 @@ discussed therein. The precedence and associativity of all the expression operators are summarized in the -grammar of SYNTAX SUMMARY. +grammar of . Otherwise, the order of evaluation of expressions is undefined. In particular, the compiler @@ -849,7 +794,7 @@ varies between machines and is usually adjustable by a library function. -Primary Expressions +Primary Expressions Primary expressions involving ., @@ -913,7 +858,7 @@ result is a pointer to the first character in the string. (There is an exception in certain initializers; -see Initialization under DECLARATIONS.) +see .) A parenthesized expression is a primary expression whose type and value are identical @@ -930,28 +875,21 @@ int, and the type of the result is .... The expression - -E1[E2] - +E1[E2] is identical (by definition) to - -*((E1)+E2)). +*((E1)+E2)). All the clues needed to understand this notation are contained in this subpart together with the discussions -in Unary Operators and Additive Operators on identifiers, - -* - +in and on identifiers, +* and - -+ - ++ respectively. The implications are summarized under Arrays, Pointers, and Subscripting -under TYPES REVISITED. +under . A function call is a primary expression followed by parentheses containing a possibly @@ -987,8 +925,7 @@ the types of actual arguments with those of formal arguments. If conversion is needed, use a cast; -see Unary Operators and Type Names under -DECLARATIONS. +see and . In preparing for the call to a function, a copy is made of each actual parameter. @@ -1015,14 +952,9 @@ an lvalue if the first expression is an lvalue. A primary expression followed by an arrow (built from - -- - +- and - -> - -) +>) followed by an identifier is an expression. The first expression must be a pointer to a structure or a union @@ -1031,17 +963,14 @@ of the structure or union to which the pointer expression points. Thus the expression - -E1->MOS - +E1->MOS is the same as - -(*E1).MOS. +(*E1).MOS. Structures and unions are discussed in -Structure, Union, and Enumeration Declarations under -DECLARATIONS. + under +. -Unary Operators +Unary Operators Expressions with unary operators group right to left. @@ -1062,9 +991,7 @@ The unary - -* - +* operator means @@ -1078,9 +1005,7 @@ the type of the result is .... The result of the unary - -& - +& operator is a pointer to the object referred to by the lvalue. @@ -1089,9 +1014,7 @@ The result of the unary - -- - +- operator is the negative of its operand. The usual arithmetic conversions are performed. @@ -1101,15 +1024,11 @@ the corresponding signed type. There is no unary - -+ - ++ operator. The result of the logical negation operator - -! - +! is one if the value of its operand is zero, zero if the value of its operand is nonzero. The type of the result is @@ -1118,67 +1037,49 @@ or to pointers. The - -~ - +~ operator yields the one's complement of its operand. The usual arithmetic conversions are performed. The type of the operand must be integral. The object referred to by the lvalue operand of prefix - -++ - +++ is incremented. The value is the new value of the operand but is not an lvalue. The expression - -++x - +++x is equivalent to x=x+1. -See the discussions Additive Operators and Assignment -Operators for information on conversions. +See the discussions and +for information on conversions. The lvalue operand of prefix - --- - +-- is decremented analogously to the prefix - -++ - +++ operator. When postfix - -++ - +++ is applied to an lvalue, the result is the value of the object referred to by the lvalue. After the result is noted, the object is incremented in the same manner as for the prefix - -++ - +++ operator. The type of the result is the same as the type of the lvalue expression. When postfix - --- - +-- is applied to an lvalue, the result is the value of the object referred to by the lvalue. After the result is noted, the object is decremented in the manner as for the prefix - --- - +-- operator. The type of the result is the same as the type of the lvalue expression. @@ -1188,22 +1089,16 @@ This construction is called a cast. -Type names are described in Type Names under Declarations. +Type names are described in . The - -sizeof - +sizeof operator yields the size in bytes of its operand. -(A - -byte - +(A byte is undefined by the language except in terms of the value of - -sizeof. +sizeof. However, in all existing implementations, a byte is the space required to hold a char.) @@ -1220,9 +1115,7 @@ like storage allocators and I/O systems. The - -sizeof - +sizeof operator may also be applied to a parenthesized type name. In that case it yields the size in bytes of an object @@ -1236,15 +1129,13 @@ is the same as (sizeof(type))-2. -Multiplicative Operators +Multiplicative Operators The multiplicative operators *, /, and - -% - +% group left to right. The usual arithmetic conversions are performed. @@ -1255,27 +1146,19 @@ The binary - -* - +* operator indicates multiplication. The - -* - +* operator is associative, and expressions with several multiplications at the same level may be rearranged by the compiler. The binary - -/ - +/ operator indicates division. The binary - -% - +% operator yields the remainder from the division of the first expression by the second. The operands must be integral. @@ -1286,29 +1169,19 @@ On all machines covered by this manual, the remainder has the same sign as the dividend. It is always true that - -(a/b)*b\ + a%b - +(a/b)*b + a%b is equal to - -a - +a (if - -b - +b is not 0). -Additive Operators +Additive Operators The additive operators - -+ - ++ and - -- - +- group left to right. The usual arithmetic conversions are performed. There are some additional type possibilities for each operator. @@ -1319,9 +1192,7 @@ The result of the - -+ - ++ operator is the sum of the operands. A pointer to an object in an array and a value of any integral type @@ -1336,30 +1207,22 @@ which points to another object in the same array, appropriately offset from the original object. Thus if - -P - +P is a pointer to an object in an array, the expression - -P+1 - +P+1 is a pointer to the next object in the array. No further type combinations are allowed for pointers. The - -+ - ++ operator is associative, and expressions with several additions at the same level may be rearranged by the compiler. The result of the - -- - +- operator is the difference of the operands. The usual arithmetic conversions are performed. Additionally, @@ -1381,16 +1244,12 @@ to objects of the same type, do not necessarily differ by a multiple of the object length. -Shift Operators +Shift Operators The shift operators - -<< - +<< and - ->> - +>> group left to right. Both perform the usual arithmetic conversions on their operands, each of which must be integral. @@ -1408,45 +1267,31 @@ The value of - -E1<<E2 - +E1<<E2 is - -E1 - +E1 (interpreted as a bit pattern) left-shifted - -E2 - +E2 bits. Vacated bits are 0 filled. The value of - -E1>>E2 - +E1>>E2 is - -E1 - +E1 right-shifted - -E2 - +E2 bit positions. The right shift is guaranteed to be logical (0 fill) if - -E1 - +E1 is unsigned; otherwise, it may be arithmetic. -Relational Operators +Relational Operators The relational operators group left to right. @@ -1458,19 +1303,12 @@ The operators - -< - +< (less than), - -> - +> (greater than), <= -(less than -or equal to), and - ->= - +(less than or equal to), and +>= (greater than or equal to) all yield 0 if the specified relation is false and 1 if it is true. @@ -1483,7 +1321,7 @@ Pointer comparison is portable only when the pointers point to objects in the same array. -Equality Operators +Equality Operators equality-expression: @@ -1492,29 +1330,19 @@ The - -== - +== (equal to) and the - -!= - +!= (not equal to) operators are exactly analogous to the relational operators except for their lower precedence. (Thus - -a<b\ ==\ c<d - +a<b == c<d is 1 whenever - -a<b - +a<b and - -c<d - +c<d have the same truth value). A pointer may be compared to an integer @@ -1525,7 +1353,7 @@ and will appear to be equal to 0. In conventional usage, such a pointer is considered to be null. -Bitwise AND Operator +Bitwise AND Operator and-expression: @@ -1533,14 +1361,10 @@ The - -& - +& operator is associative, and expressions involving - -& - +& may be rearranged. The usual arithmetic conversions are performed. The result is the bitwise @@ -1549,21 +1373,17 @@ The operator applies only to integral operands. -Bitwise Exclusive OR Operator +Bitwise Exclusive OR Operator exclusive-or-expression: expression ^ expression The - -^ - +^ operator is associative, and expressions involving - -^ - +^ may be rearranged. The usual arithmetic conversions are performed; the result is @@ -1574,21 +1394,17 @@ The operator applies only to integral operands. -Bitwise Inclusive OR Operator +Bitwise Inclusive OR Operator inclusive-or-expression: expression | expression The - -| - +| operator is associative, and expressions involving - -| - +| may be rearranged. The usual arithmetic conversions are performed; the result is the bitwise inclusive @@ -1597,24 +1413,20 @@ The operator applies only to integral operands. -Logical AND Operator +Logical AND Operator logical-and-expression: expression && expression The - -&& - +&& operator groups left to right. It returns 1 if both its operands evaluate to nonzero, 0 otherwise. Unlike &, - -&& - +&& guarantees left to right evaluation; moreover, the second operand is not evaluated if the first operand is 0. @@ -1625,24 +1437,20 @@ The result is always int. -Logical OR Operator +Logical OR Operator logical-or-expression: expression || expression The - -|| - +|| operator groups left to right. It returns 1 if either of its operands evaluates to nonzero, 0 otherwise. Unlike |, - -|| - +|| guarantees left to right evaluation; moreover, the second operand is not evaluated if the value of the first operand is nonzero. @@ -1654,7 +1462,7 @@ The result is always int. -Conditional Operator +Conditional Operator conditional-expression: expression ? expression : expression @@ -1675,7 +1483,7 @@ Only one of the second and third expressions is evaluated. -Assignment Operators +Assignment Operators There are a number of assignment operators, all of which group right to left. @@ -1718,28 +1526,24 @@ The behavior of an expression of the form -E1 op = E2 +E1 op = E2 may be inferred by taking it as equivalent to -E1 = E1 op (E2); +E1 = E1 op (E2); however, - -E1 - +E1 is evaluated only once. In - -+= - ++= and -=, the left operand may be a pointer; in which case, the (integral) right operand is converted as explained -in Additive Operators. +in . All right operands and all nonpointer left operands must have arithmetic type. -Comma Operator +Comma Operator comma-expression: expression , expression @@ -1753,8 +1557,8 @@ This operator groups left to right. In contexts where comma is given a special meaning, e.g., in lists of actual arguments -to functions (see Primary Expressions) and lists -of initializers (see Initialization under DECLARATIONS), +to functions (see ) and lists +of initializers (see ), the comma operator as described in this subpart can only appear in parentheses. For example, @@ -1762,9 +1566,8 @@ has three arguments, the second of which has the value 5. - -Declarations - +Declarations + Declarations are used to specify the interpretation which C gives to each identifier; they do not necessarily reserve storage associated with the identifier. @@ -1786,7 +1589,7 @@ The list must be self-consistent in a way described below. -Storage Class Specifiers +Storage Class Specifiers The sc-specifiers are: @@ -1802,8 +1605,8 @@ typedef specifier does not reserve storage and is called a storage class specifier only for syntactic convenience. -See Typedef for more information. -The meanings of the various storage classes were discussed in Names. +See for more information. +The meanings of the various storage classes were discussed in . The auto, @@ -1815,7 +1618,7 @@ In the extern case, -there must be an external definition (see External Definitions) +there must be an external definition (see ) for the given identifiers somewhere outside the function in which they are declared. @@ -1828,16 +1631,12 @@ Only the first few such declarations in each function are effective. Moreover, only variables of certain types will be stored in registers; -on the -PDP-11, -they are +on the PDP-11, they are int or pointer. One other restriction applies to register variables: the address-of operator - -& - +& cannot be applied to them. Smaller, faster programs can be expected if register declarations are used appropriately, @@ -1854,7 +1653,7 @@ Exception: functions are never automatic. -Type Specifiers +Type Specifiers The type-specifiers are @@ -1888,15 +1687,13 @@ If the type-specifier is missing from a declaration, it is taken to be int. -Specifiers for structures, unions, and enumerations are discussed in -Structure, Union, and Enumeration Declarations. +Specifiers for structures and unions are discussed in +. Declarations with - -typedef - -names are discussed in Typedef. +typedef +names are discussed in . -Declarators +Declarators The declarator-list appearing in a declaration is a comma-separated sequence of declarators, @@ -1911,7 +1708,7 @@ declarator initializeropt -Initializers are discussed in Initialization. +Initializers are discussed in . The specifiers in the declaration indicate the type and storage class of the objects to which the declarators refer. @@ -1928,7 +1725,7 @@ The grouping is the same as in expressions. -Meaning of Declarators +Meaning of Declarators Each declarator is taken to be an assertion that when a construction of @@ -1951,55 +1748,39 @@ T D1 where - -T - +T is a type-specifier (like int, etc.) and - -D1 - +D1 is a declarator. Suppose this declaration makes the identifier have type ... - -T - +T , where the ... is empty if - -D1 - +D1 is just a plain identifier (so that the type of - -x - +x in int x is just int). Then if - -D1 - +D1 has the form *D the type of the contained identifier is ... pointer to - -T - -\&. +T +&. If - -D1 - +D1 has the form D() @@ -2008,9 +1789,7 @@ ... function returning T. If - -D1 - +D1 has the form D[constant-expression] @@ -2029,7 +1808,7 @@ , whose type is int, and whose value is positive. -(Constant expressions are defined precisely in Constant Expressions.) +(Constant expressions are defined precisely in ) When several array of specifications are adjacent, a multidimensional array is created; the constant expressions which specify the bounds @@ -2065,39 +1844,27 @@ declares an integer i, a pointer - -ip - +ip to an integer, a function - -f - +f returning an integer, a function - -fip - +fip returning a pointer to an integer, and a pointer - -pfi - +pfi to a function which returns an integer. It is especially useful to compare the last two. The binding of - -*fip() - +*fip() is - -*(fip()). +*(fip()). The declaration suggests, and the same construction in an expression requires, the calling of a function - -fip. +fip. Using indirection through the (pointer) result to yield an integer. In the declarator @@ -2124,9 +1891,7 @@ declares a static 3-dimensional array of integers, with rank 3×5×7. In complete detail, - -x3d - +x3d is an array of three items; each item is an array of five arrays; each of the latter arrays is an array of seven @@ -2135,15 +1900,13 @@ x3d, x3d[i], x3d[i][j], - -x3d[i][j][k] - +x3d[i][j][k] may reasonably appear in an expression. The first three have type array and the last has type int. -Structure and Union Declarations +Structure and Union Declarations A structure is an object consisting of a sequence of named members. @@ -2248,9 +2011,7 @@ In all implementations, there are no arrays of fields, and the address-of operator - -& - +& may not be applied to them, so that there are no pointers to fields. @@ -2322,14 +2083,10 @@ struct tnode s, *sp; declares - -s - +s to be a structure of the given sort and - -sp - +sp to be a pointer to a structure of the given sort. With these declarations, the expression @@ -2337,13 +2094,9 @@ sp->count refers to the - -count - +count field of the structure to which - -sp - +sp points; s.left @@ -2356,24 +2109,17 @@ s.right->tword[0] refers to the first character of the - -tword - +tword member of the right subtree of - -s. - +s. -Initialization +Initialization A declarator may specify an initial value for the identifier being declared. The initializer is preceded by - -= - -and -consists of an expression or a list of values nested in braces. += +and consists of an expression or a list of values nested in braces. initializer: = expression @@ -2390,7 +2136,7 @@ All the expressions in an initializer for a static or external variable must be constant -expressions, which are described in CONSTANT EXPRESSIONS, +expressions, which are described in , or expressions which reduce to the address of a previously declared variable, possibly offset by a constant expression. Automatic or register variables may be initialized by arbitrary @@ -2446,9 +2192,7 @@ int x[] = { 1, 3, 5 }; declares and initializes - -x - +x as a one-dimensional array which has three members, since no size was specified and there are three initializers. @@ -2467,19 +2211,13 @@ y[0][0], y[0][1], and - -y[0][2]. +y[0][2]. Likewise, the next two lines initialize - -y[1] - +y[1] and - -y[2]. +y[2]. The initializer ends early and therefore - -y[3] - +y[3] is initialized with 0. Precisely, the same effect could have been achieved by @@ -2490,22 +2228,15 @@ The initializer for - -y - +y begins with a left brace but that for - -y[0] - +y[0] does not; therefore, three elements from the list are used. Likewise, the next three are taken successively for - -y[1] - +y[1] and - -y[2]. +y[2]. Also, float y[4][3] = @@ -2514,9 +2245,7 @@ }; initializes the first column of - -y - +y (regarded as a two-dimensional array) and leaves the rest 0. @@ -2527,7 +2256,7 @@ shows a character array whose members are initialized with a string. -Type Names +Type Names In two contexts (to specify type conversions explicitly by means of a cast @@ -2581,7 +2310,7 @@ pointer to function returning an integer, and array of three pointers to functions returning an integer. -Typedef +Typedef Declarations whose storage class is typedef @@ -2601,7 +2330,7 @@ equivalent to the type keyword naming the type associated with the identifier -in the way described in Meaning of Declarators. +in the way described in . For example, after @@ -2615,25 +2344,17 @@ complex z, *zp; are all legal declarations; the type of - -distance - +distance is int, that of - -metricp - +metricp is pointer to int, and that of - -z - +z is the specified structure. The - -zp - +zp is a pointer to such a structure. The @@ -2642,20 +2363,17 @@ types which could be specified in another way. Thus in the example above - -distance - +distance is considered to have exactly the same type as any other int object. - -Statements - + +Statements Except as indicated, statements are executed in sequence. -Expression Statement +Expression Statement Most statements are expression statements, which have the form @@ -2666,7 +2384,7 @@ Usually expression statements are assignments or function calls. -Compound Statement or Block +Compound Statement or Block So that several statements can be used where one is expected, the compound statement (also, and equivalently, called block) is provided: @@ -2708,7 +2426,7 @@ declarations do not reserve storage so initialization is not permitted. -Conditional Statement +Conditional Statement The two forms of the conditional statement are @@ -2723,20 +2441,15 @@ if the expression is 0. The else ambiguity is resolved by connecting an - -else - +else with the last encountered else-less - -if. +if. -While Statement +While Statement The - -while - +while statement has the form while ( expression ) statement @@ -2748,12 +2461,10 @@ The test takes place before each execution of the statement. -Do Statement +Do Statement The - -do - +do statement has the form do statement while ( expression ) ; @@ -2764,12 +2475,10 @@ The test takes place after each execution of the statement. -For Statement +For Statement The - -for - +for statement has the form: for ( exp-1opt ; exp-2opt ; exp-3opt ) statement @@ -2779,7 +2488,7 @@ this statement is equivalent to exp-1 ; -while ( exp-2\ ) +while ( exp-2 ) { statement exp-3 ; @@ -2801,20 +2510,16 @@ makes the implied - -while - +while clause equivalent to while(1); other missing expressions are simply dropped from the expansion above. -Switch Statement +Switch Statement The - -switch - +switch statement causes control to be transferred to one of several statements depending on the value of an expression. @@ -2839,7 +2544,7 @@ int. No two of the case constants in the same switch may have the same value. -Constant expressions are precisely defined in CONSTANT EXPRESSIONS. +Constant expressions are precisely defined in . There may also be at most one statement prefix of the form @@ -2848,9 +2553,7 @@ When the - -switch - +switch statement is executed, its expression is evaluated and compared with each case constant. If one of the case constants is @@ -2870,17 +2573,13 @@ switch is executed. The prefixes - -case - +case and - -default - +default do not alter the flow of control, which continues unimpeded across such prefixes. To exit from a switch, see -Break Statement. +. Usually, the statement that is the subject of a switch is compound. Declarations may appear at the head of this @@ -2889,7 +2588,7 @@ initializations of automatic or register variables are ineffective. -Break Statement +Break Statement The statement @@ -2905,7 +2604,7 @@ control passes to the statement following the terminated statement. -Continue Statement +Continue Statement The statement @@ -2949,25 +2648,18 @@ a - -continue - +continue is equivalent to - -goto\ contin. +goto contin. (Following the - -contin: - -is a null statement, see Null Statement.) +contin: +is a null statement, see .) -Return Statement +Return Statement A function returns to its caller by means of the - -return - +return statement which has one of the forms @@ -2986,7 +2678,7 @@ equivalent to a return with no returned value. The expression may be parenthesized. -Goto Statement +Goto Statement Control may be transferred unconditionally by means of the statement @@ -2995,10 +2687,10 @@ The identifier must be a label -(see Labeled Statement) +(see ) located in the current function. -Labeled Statement +Labeled Statement Any statement may be preceded by label prefixes of the form @@ -3008,13 +2700,12 @@ which serve to declare the identifier as a label. The only use of a label is as a target of a - -goto. +goto. The scope of a label is the current function, excluding any subblocks in which the same identifier has been redeclared. -See SCOPE RULES. +See -Null Statement +Null Statement The null statement has the form @@ -3022,17 +2713,14 @@ A null statement is useful to carry a label just before the - -} - +} of a compound statement or to supply a null body to a looping statement such as - -while. +while. - -External Definitions - + +External Definitions + A C program consists of a sequence of external definitions. An external definition declares an identifier to have storage class @@ -3042,9 +2730,8 @@ static, and a specified type. -The type-specifier (see Type Specifiers in -DECLARATIONS) may also be empty, in which -case the type is taken to be +The type-specifier (see ) +may also be empty, in which case the type is taken to be int. The scope of external definitions persists to the end of the file in which they are declared just as the effect @@ -3053,7 +2740,8 @@ as that of all declarations except that only at this level may the code for functions be given. -External Function Definitions + +External Function Definitions Function definitions have the form @@ -3068,8 +2756,7 @@ extern or static; -see Scope of Externals in -SCOPE RULES for the distinction between them. +see for the distinction between them. A function declarator is similar to a declarator for a function returning ... except that it lists the formal parameters of @@ -3116,13 +2803,9 @@ Here int is the type-specifier; - -max(a, b, c) - +max(a, b, c) is the function-declarator; - -int a, b, c; - +int a, b, c; is the declaration-list for the formal parameters; @@ -3149,7 +2832,8 @@ declarations of formal parameters declared array of ... are adjusted to read pointer to .... -External Data Definitions + +External Data Definitions An external data definition has the form @@ -3167,9 +2851,8 @@ or register. - -Scope Rules - + +Scope Rules A C program need not all be compiled at the same time. The source text of the program @@ -3193,7 +2876,7 @@ that references to the same external identifier are references to the same object. -Lexical Scope +Lexical Scope The lexical scope of identifiers declared in external definitions persists from the definition through @@ -3213,17 +2896,12 @@ any declaration of that identifier outside the block is suspended until the end of the block. -Remember also (see Structure, Union, and Enumeration Declarations in -DECLARATIONS) that tags, identifiers associated with +Remember also (see ) that identifiers associated with ordinary variables, -and identities associated with structure and union members -form three disjoint classes -which do not conflict. +and those associated with structure and union members +form two disjoint classes which do not conflict. Members and tags follow the same scope rules as other identifiers. -The enum constants are in the same -class as ordinary variables and follow the same scope rules. -The typedef names are in the same class as ordinary identifiers. They may be redeclared in inner blocks, but an explicit @@ -3242,10 +2920,10 @@ must be present in the second declaration, or it would be taken to be a declaration with no declarators and type - -distance. +distance. -Scope of Externals + +Scope of Externals If a function refers to an identifier declared to be extern, @@ -3287,16 +2965,14 @@ Functions may be declared static. - +<sect1 id="cref12"><title> Compiler Control Lines The C compiler contains a preprocessor capable of macro substitution, conditional compilation, and inclusion of named files. Lines beginning with - -# - +# communicate with this preprocessor. There may be any number of blanks and horizontal tabs @@ -3347,9 +3023,7 @@ In both forms a long definition may be continued on another line by writing - -\ - +\ at the end of the line to be continued. This facility is most valuable for definition of manifest constants, @@ -3406,7 +3080,7 @@ #if constant-expression checks whether the constant expression evaluates to nonzero. -(Constant expressions are discussed in CONSTANT EXPRESSIONS. +(Constant expressions are discussed in . A control line of the form #ifdef identifier @@ -3414,9 +3088,7 @@ checks whether the identifier is currently defined in the preprocessor; i.e., whether it has been the subject of a - -#define - +#define control line. It is equivalent to #ifdef(identifier). A control line of the form @@ -3443,25 +3115,17 @@ If the checked condition is true, then any lines between - -#else - +#else and - -#endif - +#endif are ignored. If the checked condition is false, then any lines between the test and a - -#else - +#else or, lacking a #else, the - -#endif - +#endif are ignored. These constructions may be nested. @@ -3479,7 +3143,7 @@ file is named by the identifier. If the identifier is absent, the remembered file name does not change. - +<sect1 id="cref13"><title> Implicit Declarations It is not always necessary to specify @@ -3508,21 +3172,18 @@ In an expression, an identifier followed by - -( - +( and not already declared is contextually declared to be function returning int. - -Types Revisited - + +Types Revisited This part summarizes the operations which can be performed on objects of certain types. -Structures and Unions +Structures and Unions Structures and unions may be assigned, passed as arguments to functions, and returned by functions. @@ -3546,7 +3207,7 @@ it is permitted to inspect the common initial part of any of the contained structures. -Functions +Functions There are only two things that can be done with a function m, @@ -3563,9 +3224,7 @@ Then the definition of - -g - +g might read g(funcp) @@ -3578,21 +3237,15 @@ Notice that - -f - +f must be declared explicitly in the calling routine since its appearance in - -g(f) - +g(f) was not followed by - -(. - +(. -Arrays, Pointers, and Subscripting +Arrays, Pointers, and Subscripting Every time an identifier of array type appears in an expression, it is converted into a pointer @@ -3633,17 +3286,13 @@ of rank i×j×...×k, then - -E - +E appearing in an expression is converted to a pointer to an (n-1)-dimensional array with rank j×...×k. If the - -* - +* operator, either explicitly or implicitly as a result of subscripting, is applied to this pointer, @@ -3656,34 +3305,24 @@ Here - -x - +x is a 3×5 array of integers. When - -x - +x appears in an expression, it is converted to a pointer to (the first of three) 5-membered arrays of integers. In the expression x[i], which is equivalent to *(x+i), - -x - +x is first converted to a pointer as described; then - -i - +i is converted to the type of x, which involves multiplying - -i - +i by the length the object to which the pointer points, namely 5-integer objects. @@ -3704,8 +3343,8 @@ Certain conversions involving pointers are permitted but have implementation-dependent aspects. They are all specified by means of an explicit type-conversion -operator, see Unary Operators underEXPRESSIONS and -Type Namesunder DECLARATIONS. +operator, see and +. A pointer may be converted to any of the integral types large enough to hold it. @@ -3783,35 +3422,30 @@ 2-byte boundaries. Arrays of characters, all structures, ints, longs, floats, and doubles are aligned on 4-byte boundries; but structure members may be packed tighter. - -CONSTANT EXPRESSIONS + +Constant Expressions -In several places C requires expressions that evaluate to +In several places C requires expressions which evaluate to a constant: -after -case, +after case, as array bounds, and in initializers. In the first two cases, the expression can involve only integer constants, character constants, -casts to integral types, -enumeration constants, and - -sizeof - +sizeof expressions, possibly connected by the binary operators - + + - * / % & | ^ << >> == != < > <= >= && || - + or by the unary operators - + - ~ - + or by the ternary operator - + ?: - + Parentheses can be used for grouping but not for function calls. @@ -3821,24 +3455,20 @@ one can also use floating constants and arbitrary casts and can also apply the unary - -& - +& operator to external or static objects and to external or static arrays subscripted with a constant expression. The unary - -& - +& can also be applied implicitly by appearance of unsubscripted arrays and functions. The basic rule is that initializers must evaluate either to a constant or to the address of a previously declared external or static object plus or minus a constant. - - +</para></sect1> +<sect1 id="cref16"><title> Portability Considerations Certain parts of C are inherently machine dependent. @@ -3906,7 +3536,7 @@ bitfields, and does not accept a few assignment operators in certain contexts where the value of the assignment is used. -Anachronisms +Anachronisms Since C is an evolving language, certain obsolete constructions may be found in older programs. Although most versions of the compiler support @@ -3914,7 +3544,8 @@ problem behind. -Earlier versions of C used the form =op instead of op= for assignment +Earlier versions of C used the form =op instead +of op= for assignment operators. This leads to ambiguities, typified by: x=-1 @@ -3938,7 +3569,7 @@ resembles a function declaration closely enough to confuse the compilers. -Syntax Summary +Syntax Summary This summary of C syntax is intended more for aiding comprehension than as an exact statement of the language. @@ -4171,7 +3802,8 @@ ; -External definitions + +External definitions program: diff -r 9f274edaf94f -r c8fcb9426d8b docs/ccguide/errors.appendix --- a/docs/ccguide/errors.appendix Mon Mar 31 19:21:49 2003 +0000 +++ b/docs/ccguide/errors.appendix Mon Mar 31 21:47:18 2003 +0000 @@ -10,7 +10,7 @@ Variable has already been declared at the current block level. -(8.1, 9.2) +(, ) @@ -28,7 +28,7 @@ Function argument declared as type struct, union or function. -Pointers to such types, however are allowed. (10.1) +Pointers to such types, however are allowed. () @@ -37,7 +37,7 @@ Function arguments may only be declared as storage class -register. (10.1) +register. () @@ -54,7 +54,7 @@ both must be integral ->> and << operands cannot be FLOAT or DOUBLE. (7.5) +>> and << operands cannot be FLOAT or DOUBLE. () @@ -63,7 +63,7 @@ The break statement is allowed only inside a while, do, for or -switch block. (9.8) +switch block. () @@ -72,7 +72,7 @@ & operator not allowed in a register variable. Operand must -otherwise be an lvalue. (7.2) +otherwise be an lvalue. () @@ -80,7 +80,7 @@ cannot cast -Type result of cast cannot be FUNCTION or ARRAY. (7.2, 8.7) +Type result of cast cannot be FUNCTION or ARRAY. (, ) @@ -89,7 +89,7 @@ Could not determine size from declaration or initializer. -(8.6, 14.3) +(, ) @@ -98,7 +98,7 @@ Storage class or type does not allow variable to be -initialized. (8.6) +initialized. () @@ -117,7 +117,7 @@ While, do, for, switch and if statements require a condition -expression. (9.3) +expression. () @@ -129,7 +129,7 @@ reference variables. They may, however, refer to the address of a previously declared variable. This installation allows no initializer expressions unless all operands are of type INT or -CHAR (8.6) +CHAR () @@ -138,7 +138,7 @@ Input numeric constant was too large for the implied or -explicit type. (2.6, [PDP-11]) +explicit type. (, [PDP-11]) @@ -146,8 +146,8 @@ constant required -Variables are not allowed for array dimensions or cases. (8.3, -8.7, 9.7) +Variables are not allowed for array dimensions or cases. (, +, ) @@ -156,7 +156,7 @@ The continue statement is allowed only inside a while, do, or -for block. (9.9) +for block. () @@ -169,7 +169,7 @@ type after a reference has been made to the function. Depending on the line structure of the declaration block, this error may be reported on the line following the erroneous -declaration. (11, 11.1, 11.2) +declaration. (, , ) @@ -203,7 +203,7 @@ Statement or expression encountered outside a function. -Typically causes by mismatched braces. (10.1) +Typically causes by mismatched braces. () @@ -212,7 +212,7 @@ A function cannot be declared as returning an array, function, -struct, or union. (8.4, 10.1) +struct, or union. (, ) @@ -221,7 +221,7 @@ End-of-file encountered before the end of function definition. -(10.1) +() @@ -238,7 +238,7 @@ Declarations are allowed only at the beginning of a block. -(9.2) +() @@ -246,7 +246,7 @@ label required -Label name required on goto statement. (9.11) +Label name required on goto statement. (1) @@ -254,7 +254,7 @@ label undefined -Goto to label not defined in the current function. (9.12) +Goto to label not defined in the current function. () @@ -263,7 +263,7 @@ Left side of assigment must be able to be "stored into". -Array names, functions, structs, etc. are no lvalues. (7.1) +Array names, functions, structs, etc. are no lvalues. () @@ -271,7 +271,7 @@ multiple defaults -Only one default statement is allowed in a switch block. (9.7) +Only one default statement is allowed in a switch block. () @@ -280,7 +280,7 @@ Identifier name was declared more than once in the same block -level (9.2, 11.1) +level (, ) @@ -296,7 +296,7 @@ name clash -Struct-union member and tag names must be mutually distinct. (8.5) +Struct-union member and tag names must be mutually distinct. () @@ -304,7 +304,7 @@ name in cast -Identifier name found in a cast. Only types are allowed. (7.2, 8.7) +Identifier name found in a cast. Only types are allowed. (, ) @@ -312,7 +312,7 @@ named twice -Names in a function parameter list may appear only once. (10.1) +Names in a function parameter list may appear only once. () @@ -321,7 +321,7 @@ Else statement found with no matching if. This is typically -caused by extra or missing braces and/or semicolons. (9.3) +caused by extra or missing braces and/or semicolons. () @@ -329,7 +329,7 @@ no switch statement -Case statements can only appear within a switch block. (9.7) +Case statements can only appear within a switch block. () @@ -339,7 +339,7 @@ Primary in expression is not type "function returning...". If this is really a function call, the function name was declared -differently elsewhere. (7.1) +differently elsewhere. () @@ -347,7 +347,7 @@ not an argument -Name does not appear in the function parameter list. (10.1) +Name does not appear in the function parameter list. () @@ -357,7 +357,7 @@ Unary operators require one operand, binary operators two. This is typically caused by misplaced parenthesis, casts or -operators. (7.1) +operators. () @@ -387,7 +387,7 @@ pointer mismatch -Pointers refer to different types. Use a case if required. (7.1) +Pointers refer to different types. Use a case if required. () @@ -396,7 +396,7 @@ A pointer (of any type) or integer is required to the left of -the '->' operator. (7.1) +the '->' operator. () @@ -404,7 +404,7 @@ pointer required -Pointer operand required with unary * operator. (7.1) +Pointer operand required with unary * operator. () @@ -412,7 +412,7 @@ primary expected -Primary expression required here. (7.1) +Primary expression required here. () @@ -422,7 +422,7 @@ Second and third expression of ?: conditional operator cannot be pointers to different types. If both are pointers, they -must be of the same type or one of the two must be null. (7.13) +must be of the same type or one of the two must be null. () @@ -440,7 +440,7 @@ Reg and auto storage classes mey only be used within functions. -(8.1) +() @@ -449,7 +449,7 @@ Identical member names in two different structures must have -the same type and offset in both. (8.5) +the same type and offset in both. () @@ -458,7 +458,7 @@ Identifier used with . and -> operators must be a structure -member name. (7.1) +member name. () @@ -466,7 +466,7 @@ struct syntax -Brace, comma, etc. is missing in a struct declaration. (8.5) +Brace, comma, etc. is missing in a struct declaration. () @@ -492,7 +492,7 @@ ? must be followed by a : with expression. This error may be causes by unmatched parenthesis or other errors in the -expression. (7.13) +expression. () @@ -501,7 +501,7 @@ Too many characters provided in a string initializing a -character array. (8.6) +character array. () @@ -510,7 +510,7 @@ Unmatched or unexpected brackets encountered processiong an -initializer. (8.6) +initializer. () @@ -519,7 +519,7 @@ More data items supplied for aggregate level in initializer -than members of the aggregate. (8.6) +than members of the aggregate. () @@ -543,7 +543,7 @@ typedef - not a variable -Typedef type name cannot be used in this manner. (8.8) +Typedef type name cannot be used in this manner. () @@ -560,7 +560,7 @@ Union or struct declaration refers to an undefined structure -name. (8.5) +name. () @@ -568,7 +568,7 @@ unions not allowed -Cannot initialize union members. (8.6) +Cannot initialize union members. () @@ -576,7 +576,7 @@ unterminated character constant -Unmatched ' character delimiters. (2.4.3) +Unmatched ' character delimiters. () @@ -584,7 +584,7 @@ unterminated string -Unmatched " string delimiters. (2.5) +Unmatched " string delimiters. () @@ -592,7 +592,7 @@ while expected -No while found for do statement. (9.5) +No while found for do statement. () diff -r 9f274edaf94f -r c8fcb9426d8b docs/ccguide/makefile --- a/docs/ccguide/makefile Mon Mar 31 19:21:49 2003 +0000 +++ b/docs/ccguide/makefile Mon Mar 31 21:47:18 2003 +0000 @@ -14,7 +14,8 @@ strcat.refentry system.refentry toupper.refentry \ ungetc.refentry -APPS = asm.appendix basic09.appendix errors.appendix phases.appendix +APPS = asm.appendix basic09.appendix errors.appendix phases.appendix \ + creference.appendix SYSCALL = abort.refentry abs.refentry access.refentry chain.refentry \ chdir.refentry chmod.refentry chown.refentry close.refentry \