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

📄 c3

📁 UNIX v6源代码 这几乎是最经典的unix版本 unix操作系统设计和莱昂氏unix源代码分析都是用的该版
💻
字号:
.ta  .5i 1i 1.5i 2i 2.5i 3i.ul8.  Declarations.etDeclarations are used within function definitions to specify the interpretationwhich C gives to each identifier; they do not necessarilyreserve storage associated with the identifier.Declarations have the form.dp 2	declaration:		decl-specifiers declarator-list\*(op  \fG;.edThe declarators in the declarator-listcontain the identifiers being declared.The decl-specifiersconsist of at most one type-specifier and at mostone storage class specifier..dp 5	decl-specifiers:		type-specifier		sc-specifier		type-specifier sc-specifier		sc-specifier type-specifier.ed8.1  Storage class specifiers.etThe sc-specifiers are:.dp 4	sc-specifier:.ft G		auto		static		extern		register.edThe.bd "auto, static,"and.bd registerdeclarations also serve as definitionsin that they cause an appropriate amount of storage to be reserved.In the \fGextern\fR casethere must be an external definition (see below)for the given identifierssomewhere outside the function in which they are declared..pgThere are some severe restrictions on.bd registeridentifiers:there can be at most 3 register identifiers in any function,and the type of a register identifier can only be.bd int,.bd char,or pointer (not.bd float,.bd double,structure, function, or array).Also the address-ofoperator.bd &cannot be applied to such identifiers..aExcept for these restrictions(in return for which one is rewarded with faster, smaller code),register identifiers behave as if theywere automatic.In fact implementations of Care free to treat.bd registeras synonymous with.bd auto..pgIf the sc-specifier is missing from a declaration, itis generally taken to be \fGauto\fR..ms8.2  Type specifiers.etThe type-specifiers are.dp 6	type-specifier:		\fGint\fR		\fGchar\fR		\fGfloat		\fGdouble		struct \fI{ type-decl-list }\fG		struct \fIidentifier { type-decl-list }\fG		struct \fIidentifier.edThe \fGstruct\fR specifier is discussed in \(sc8.5.If the type-specifier is missing from a declaration,it is generally taken to be \fGint\fR..ms8.3  Declarators.etThe declarator-list appearing in a declarationis a comma-separated sequence of declarators..dp 2	declarator-list:		declarator		declarator \fG,\fI declarator-list.edThe specifiers in the declarationindicate the type and storage class of the objects to which thedeclarators refer.Declarators have the syntax:.dp 6	declarator:		identifier		\fG\**\fI declarator		declarator \fG( )\fI		declarator \fG[ \fIconstant-expression\*(op \fG]		\fG( \fIdeclarator \fG).edThe grouping in this definition isthe same as in expressions..ms8.4  Meaning of declarators.etEach declarator is taken to bean assertion that when a construction ofthe same form as the declarator appears in an expression,it yields an object of the indicatedtype and storage class.Each declarator contains exactly one identifier; it is this identifier thatis declared..pgIf an unadorned identifier appearsas a declarator, then it has the typeindicated by the specifier heading the declaration..pgIf a declarator has the form.sp .7	\** D.sp .7for D a declarator, then thecontained identifier has the type ``pointer to .^.^.'', where``^.^.^.^'' is the type which the identifier would have hadif the declarator had been simply D..pgIf a declarator has the form.sp .7	D^(^^).sp .7then the contained identifier has the type``function returning ...'', where ``^.^.^.^'' is thetype which the identifier would havehad if the declarator had been simply D..pgA declarator may have the form.sp .7	D[constant-expression].sp .3or.sp .3	D[^^].sp .7In the first case the constantexpressionis an expressionwhose value is determinable at compile time,and whose type is.ft Gint..ft Rin the second the constant 1 is used.(Constant expressions are defined precisely in \(sc15.)^^Such a declarator makes the contained identifier havetype ``array.''If the unadorned declarator D wouldspecify a non-array of type ``.^.^.'',then the declarator``D[^i^]''yields a 1-dimensional array with rank \fIi\fR of objectsof type ``.^.^.''.If the unadorned declarator D wouldspecify an \fIn^\fR-dimensional arraywith rank.ft Ii\s6\d1\u\s10^\(mu^i\s6\d2\u\s10^\(mu^.^.^.^\(mu^i\s6\dn\u\s10,.ft Rthen the declarator ``D[^i\s6\dn+1\u\s10^]''yields an (\fIn^\fR+1^)\fR^-dimensionalarray with rank.ft Ii\s6\d1\u\s10^\(mu^i\s6\d2\u\s10^\(mu^.^.^.^\(mu^i\s6\dn\u\s10\^\(mu^i\s6\dn+1\u\s10\fR..pgAn array may be constructed from one of the basic types, from a pointer,from a structure,or from another array (to generate a multi-dimensional array)..pgFinally, parentheses in declarators do not alter the typeof the contained identifierexcept insofar as they alter the bindingof the components of the declarator..pgNot all the possibilitiesallowed by the syntax above are actuallypermitted.The restrictions are as follows:functions may not returnarrays, structures or functions,although they may return pointers to such things;there are no arrays of functions, althoughthere may be arrays of pointers to functions.Likewise a structure may not contain a function,but it may contain a pointer to a function..pgAs an example, the declaration.sp .7.bG	int i, \**ip, f^(^^), \**fip(^^), (\**pfi)^(^^);.eG.sp .7declares an integer \fIi\fR,a pointer \fIip\fR to an integer,a function \fIf\fR returning an integer,a function \fIfip\fR returning a pointer to an integer,and a pointer \fIpfi\fR to a function whichreturns an integer.Also.sp .7.bG	float fa[17], \**afp[17];.eG.sp .7declares an array of \fGfloat\fR numbers and an array ofpointers to \fGfloat\fR numbers.Finally,.sp .7.bG	static int x3d[3][5][7];.sp .7.eGdeclares a static three-dimensional array of integers,with rank 3\(mu5\(mu7.In complete detail, \fIx3d\fR is an array of three items:each item is an array of five arrays;each of the latter arrays is an array of sevenintegers.Any of the expressions ``x3d'', ``x3d[^i^]'', ``x3d[^i^][^j^]'', ``x3d[^i^][^j^][^k^]''may reasonably appear in an expression.The first three have type ``array'',the last has type \fGint\fR..ms8.5  Structure declarations.etRecall that one of the forms for a structure specifieris.dp		\fGstruct \fI{ type-decl-list }.edThe.ft Itype-decl-list.ft Ris a sequence of type declarations for the members of the structure:.dp 3	type-decl-list:		type-declaration		type-declaration type-decl-list.edA type declaration is just a declaration which does notmention a storage class (the storage class ``member ofstructure'' here being understood by context)..dp 2	type-declaration:		type-specifier declarator-list  \fG;.edWithin the structure, the objects declaredhave addresses which increase as their declarationsare read left-to-right.Each component of a structurebegins on an addressing boundary appropriateto its type.On the \s8PDP\s10-11 the only requirement is that non-charactersbegin on a word boundary; therefore, there maybe 1-byte, unnamed holes in a structure,and all structureshave an even length in bytes..pgAnother form of structure specifier is.dp 1		\fGstruct \fIidentifier { type-decl-list }.edThis form is the same as the one just discussed,except that the identifier is rememberedas the.ft Istructure tag.ft Rof the structure specified by the list.A subsequent declaration may then be givenusing the structure tag but without the list,as in the third form of structure specifier:.dp		\fGstruct \fIidentifier.edStructure tags allow definition of self-referentialstructures; they alsopermit the long part of the declaration to begiven once and used several times.It is however absurd to declare a structurewhich contains an instance ofitself, as distinct from a pointer to an instance of itself..pgA simple example of a structure declaration, taken from\(sc16.2 where its use is illustrated more fully, is.dp 6.bG	struct tnode {		char tword[20];		int count;		struct tnode \**left;		struct tnode \**right;	};.ed.eGwhich contains an array of 20 characters, an integer, and two pointersto similar structures.Once this declaration has been given, the followingdeclaration makes sense:.sp .7.bG	struct tnode s, \**sp;.br.eG.sp .7which declares\fIs\fR to be a structure of the given sortand \fIsp\fR to be a pointer to a structureof the given sort..pgThe names of structure members and structure tags maybe the same as ordinary variables, since a distinctioncan be made by context.However, names of tags and membersmust be distinct.The same member name can appear in differentstructures only if the two members are of the same typeand if their origin with respect to their structure is thesame;thus separate structures can share a common initial segment.

⌨️ 快捷键说明

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