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

📄 ct8

📁 UNIX v6源代码 这几乎是最经典的unix版本 unix操作系统设计和莱昂氏unix源代码分析都是用的该版
💻
字号:
.NHBit Operators.PPC has several operators for logical bit-operations.For example,.E1x = x & 0177;.E2forms the bit-wise .UC ANDof.UL xand 0177,effectively retaining only the last seven bits of .UL x\*.Other operators are.E1.ft R\(or	inclusive OR^	(circumflex) exclusive OR.tr+~+	(tilde) 1's complement.tr++!	logical NOT<<	left shift (as in x<<2)>>	right shift	(arithmetic on PDP\(hy11; logical on H6070, IBM360).E2.NHAssignment Operators.PPAn unusual feature of Cis that the normal binary operators like`+', `\(mi', etc.can be combined with the assignment operator `='to form new assignment operators.For example,.E1x =- 10;.E2uses the assignment operator `=\(mi' to decrement .UL xby 10,and.E1x =& 0177.E2forms the.UC ANDof .UL xand 0177.This convention is a useful notational shortcut,particularly if.UL xis a complicated expression.The classic example is summing an array:.E1for( sum=i=0; i<n; i\*+ )	sum =+ array[i];.E2But the spaces around the operator are critical!For instance,.E1x = -10;.E2sets.UL xto\(mi10, while.E1x =- 10;.E2subtracts 10 from.UL x\*.When no space is present,.E1x=-10;.E2also decreases .UL xby 10.This is quite contrary to the experience of most programmers.In particular, watch out for things like.E1c=\**s\*+;y=&x[0];.E2both of which are almost certainly not what you wanted.Newer versions of various compilers are courteous enough to warn you about the ambiguity..PPBecause all other operators in an expression are evaluatedbefore the assignment operator,the order of evaluation should be watched carefully:.E1x = x<<y | z;.E2means``shift.UL xleft.UL yplaces,then.UC ORwith.UL z,and store in.UL x\*.''But.E1x =<< y | z;.E2means``shift.UL xleft by.UL y|zplaces'',which is rather different..NHFloating Point.PPWe've skipped over floating point so far,and the treatment here will be hasty.C has single and double precision numbers(where the precision depends on the machine at hand).For example,.E1	double sum;	float avg, y[10];	sum = 0\*.0;	for( i=0; i<n; i\*+ )		sum =+ y[i];	avg = sum/n;.E2forms the sum and average of the array.UL y\*..PPAll floating arithmetic is done in double precision.Mixed mode arithmetic is legal;if an arithmetic operator in an expressionhas both operands.UL intor.UL char,the arithmetic done is integer, butif one operand is.UL intor.UL charand the other is.UL floator.UL double,both operands are converted to.UL double\*.Thus if.UL iand.UL jare.UL intand.UL xis.UL float,.E1(x+i)/j		converts i and j to floatx + i/j		does i/j integer, then converts.E2Type conversionmay be made by assignment;for instance,.E1	int m, n;	float x, y;	m = x;	y = n;.E2converts.UL xto integer(truncating toward zero),and.UL nto floating point..PPFloating constants are just like those in Fortran or PL/I,except that the exponent letter is `e' instead of `E'.Thus:.E1	pi = 3\*.14159;	large = 1\*.23456789e10;.E2.PP.UL printfwill format floating point numbers:.UL ``%w\*.df''in the format string will print the corresponding variablein a field.UL wdigits wide, with.UL ddecimal places.An.UL einstead of an.UL fwill produce exponential notation..NHHorrors! goto's and labels.PPC has a.UL gotostatement and labels, so you can branch aboutthe way you used to.But most of the time.UL goto'saren't needed.(How many have we used up to this point?)The code can almost always be more clearly expressed by.UL for/while,.UL if/else,and compound statements..PPOne use of.UL goto'swith some legitimacy is in a programwhichcontains a long loop,where a.UL while(1)would be too extended.Then you might write.E1   mainloop:	\*.\*.\*.	goto mainloop;.E2Another use is to implement a.UL breakout of more than one level of.UL foror .UL while\*..UL goto'scan only branch to labels within the same function..NHAcknowledgements.PPI am indebted to a veritable host of readers who madevaluable criticisms on several drafts of this tutorial.They ranged in experience from complete beginnersthrough several implementors of C compilersto the C language designer himself.Needless to say, this is a wide enough spectrum of opinionthat no one is satisfied (including me);comments and suggestions are still welcome,so that some future version might be improved.

⌨️ 快捷键说明

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