⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c2

📁 UNIX v6源代码 这几乎是最经典的unix版本 unix操作系统设计和莱昂氏unix源代码分析都是用的该版
💻
📖 第 1 页 / 共 2 页
字号:
.ul7.  Expressions.etThe precedence of expression operators is the sameas the order of the majorsubsections of this section (highest precedence first).Thus the expressions referred to as the operands of \fG+\fR(\(sc7.4)are those expressions defined in \(sc\(sc7.1_7.3.Within each subsection, the operators have the sameprecedence.Left- or right-associativity is specifiedin each subsection for the operatorsdiscussed therein.The precedence and associativity of all the expressionoperators is summarized in anappendix..pgOtherwise the order of evaluation of expressionsis undefined.  In particular the compilerconsiders itself free tocompute subexpressions in the order it believesmost efficient,even if the subexpressionsinvolve side effects..ms7.1  Primary expressions.etPrimary expressionsinvolving \fG.\fR^, \fG\(mi>\fR, subscripting, and function callsgroup left to right..ms7.1.1  \fIidentifier\fR.etAn identifier is a primary expression, provided it has beensuitably declared as discussed below.Its type is specified by its declaration.However, if the type of the identifier is ``array of .^.^.'',then the value of the identifier-expressionis a pointerto the first object in the array, and thetype of the expression is``pointer to .^.^.''.Moreover, an array identifier is not an lvalueexpression..pgLikewise, an identifier which is declared``function returning .^.^.'',when used except in the function-name positionof a call, is converted to ``pointer to function returning .^.^.''..ms7.1.2  \fIconstant\fR.etA decimal, octal, character, or floatingconstant is a primary expression.Its type is \fGint\fR in the first three cases,\fGdouble\fR in the last..ms7.1.3  \fIstring\fR.etA string is a primary expression.Its type is originally ``array of \fGchar\fR''; but followingthe same rule as in \(sc7.1.1 for identifiers,this is modified to ``pointer to \fGchar\fR'' and theresult is a pointer to the first characterin the string..ms7.1.4  \fG(\fI expression \fG)\fR.etA parenthesized expression is a primary expressionwhose type and value are identicalto those of the unadorned expression.The presence of parentheses doesnot affect whether the expression is anlvalue..ms7.1.5  \fIprimary-expression\fG [\fI expression \fG]\fR.etA primary expression followed by an expression in squarebrackets is a primary expression.The intuitive meaning is that of a subscript.Usually, the primary expression has type ``pointer to .^.^.'',the subscript expression is \fGint\fR,and the type of the result is ``^.^.^.^''.The expression ``E1[E2]'' isidentical (by definition) to ``\**^(^^(^E1^)^+^(^E2^)^^)^''.All the cluesneeded to understandthis notation are contained in this section togetherwith the discussionsin \(sc\(sc 7.1.1, 7.2.1, and 7.4.1 on identifiers,\fG\**\fR, and \fG+\fR respectively;\(sc14.3 below summarizes the implications..ms7.1.6  \fIprimary-expression \fG( \fIexpression-list\*(op \fG).etA function call is a primary expression followed by parenthesescontaining a possiblyempty, comma-separated list of expressionswhich constitute the actual arguments to thefunction.The primary expression must be of type ``function returning .^.^.'',and the result of the function call is of type ``^.^.^.^''.As indicatedbelow, a hitherto unseen identifier followedimmediately by a left parenthesisis contextually declaredto represent a function returningan integer;thus in the most common case, integer-valued functionsneed not be declared..pgAny actual arguments of type \fGfloat\fR areconverted to \fGdouble\fR before the call;any of type \fGchar\fR are converted to \fGint\fR..pgIn preparing for the call to a function,a copy is made of each actual parameter;thus, all argument-passing in C is strictly by value.A function maychange the values of its formal parameters, butthese changes cannot possibly affect the valuesof the actual parameters.On the other hand, it is perfectly possibleto pass a pointer on the understandingthat the function may change the valueof the object to which the pointer points..pgRecursive calls to anyfunction are permissible..ms7.1.7  \fIprimary-lvalue \fG.\fI member-of-structure\fR.etAn lvalue expression followed by a dot followed by the nameof a member of a structure is a primary expression.The object referred toby the lvalue is assumed to have thesame form as the structurecontaining the structure member.The result of the expression is an lvalue appropriatelyoffset from the origin of the given lvaluewhose type is that of thenamed structure member.The given lvalue is not required to haveany particular type..pgStructures are discussed in \(sc8.5..ms7.1.8  \fIprimary-expression \fG\(mi>\fI member-of-structure\fR.etThe primary-expression is assumed to be a pointerwhich points to an object of the same formas the structure of which the member-of-structure isa part.The result is an lvalue appropriatelyoffset from the origin of the pointed-to structurewhose type is that of the named structure member.The type of the primary-expression need notin fact be pointer; it is sufficient thatit be a pointer, character, or integer..pgExcept for the relaxation of the requirement thatE1 be of pointer type, the expression ``E1\(mi>MOS''is exactly equivalent to ``(\**E1).MOS''..ms7.2  Unary operators.etExpressions with unary operatorsgroup right-to-left..ms7.2.1  \fG\**\fI expression\fR.etThe unary \fG\**\fR operatormeans.ft Iindirection:.ft Rthe expression must be a pointer, and the resultis an lvalue referring to the object towhich the expression points.If the type of the expression is ``pointer to .^.^.'',the type of the result is ``^.^.^.^''..ms7.2.2  \fG&\fI lvalue-expression\fR.etThe result of the unary \fG&\fR operator is a pointerto the object referred to by thelvalue-expression.If the type of the lvalue-expression is ``^.^.^.^'',the type of the result is ``pointer to .^.^.''..ms7.2.3  \fG\(mi\fI expression\fR.etThe result is the negative of the expression,and has the same type.The type of the expression must be \fGchar\fR, \fGint\fR, \fGfloat\fR,or \fGdouble\fR..ms7.2.4  \fG!\fI expression\fR.etThe result of the logical negation operator \fG!\fRis 1 if the value of the expression is 0, 0 if the value of theexpression is non-zero.The type of the result is \fGint\fR.This operator is applicable only to \fGint\fRs or \fGchar\fRs..ms7.2.5  \fG\*~\fI expression\fR.etThe \*~ operator yields the one's complement of its operand.The type of the expression must be \fGint\fR or \fGchar\fR,and the result is \fGint\fR..ms7.2.6  ++ \fIlvalue-expression\fR.etThe object referred to by the lvalue expressionis incremented.The value is the new value of the lvalue expressionand the type is the type of the lvalue.If the expression is \fGint\fR or \fGchar\fR,it is incremented by 1;if it is a pointer to an object, it is incrementedby the length of the object.++ is applicable only to these types.(Not, for example, to \fGfloat\fR or \fGdouble\fR.).ms7.2.7  \fR\(mi\(mi\fI lvalue-expression\fR.etThe object referred to by the lvalue expression is decrementedanalogously to the ++ operator..ms7.2.8  \fIlvalue-expression ++.etThe result is the value of the objectreferred to by the lvalue expression.After the result is noted, the objectreferred to by the lvalue is incremented in the samemanner as for the prefix ++ operator: by 1 for an \fGint\fRor \fGchar\fR, by the length of the pointed-to object for a pointer.The type of the result is the same as thetype of the lvalue-expression..ms7.2.9  \fIlvalue-expression \(mi\(mi.etThe result of the expression is the value of the objectreferred to by thethe lvalue expression.After the result is noted, the object referredto by the lvalue expression is decremented in a wayanalogous to the postfix ++ operator..ms7.2.10  \fGsizeof \fIexpression.etThe \fGsizeof\fR operator yields the size,in bytes, of its operand.When applied to an array, the result is the totalnumber of bytes in the array.The size is determined fromthe declarations ofthe objects in the expression.This expression is semantically an integer constant and maybe used anywhere a constant is required.Its major use is in communication with routineslike storage allocators and I/O systems..ms7.3  Multiplicative operators.etThe multiplicative operators\fG\**\fR, \fG/\fR, and \fG%\fRgroup left-to-right..ms7.3.1  \fIexpression\fG \** \fIexpression\fR.etThe binary \fG\**\fR operator indicates multiplication.If both operands are \fGint\fR or \fGchar\fR, the resultis \fGint\fR; if one is \fGint\fR or \fGchar\fR and one \fGfloat\fR or \fGdouble\fR, the

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -