【正文】
– For example, op1 = op1 3。 A First Book of ANSI C, Fourth Edition 27 The Shift Operators (continued) A First Book of ANSI C, Fourth Edition 28 The Shift Operators (continued) A First Book of ANSI C, Fourth Edition 29 The Shift Operators (continued) ? The type of fill shown in Figures and , where the sign bit is reproduced in vacated bit positions, is known as an arithmetic right shift – In an arithmetic right shift, each single shift to the right corresponds to a division by 2 – Some puters automatically fill the vacated bits with 0s。 this type of shift is known as a logical shift ? For positive signed numbers, where the leftmost bit is 0, both arithmetic and logical right shifts produce the same result A First Book of ANSI C, Fourth Edition 30 Macros ? In its simplest form, the define preprocessor is used to equate constants and operators to symbolic names – define SALESTAX ? The substitutions are made by the C preprocessor just prior to program pilation ? C places no restrictions on the equivalences that can be established with the define statement ? When the equivalence consists of more than a single value, operator, or variable, the symbolic name is referred to as a macro A First Book of ANSI C, Fourth Edition 31 Macros (continued) ? For example, the equivalence established by the statement… define FORMAT The answer is %f\n …enables us to write the statement – printf(FORMAT, )。 ? The piler always receives the expanded version after the text has been inserted in place of the symbolic name by the preprocessor A First Book of ANSI C, Fourth Edition 32 Macros (continued) ? Equivalences can use arguments – define SQUARE(x) x * x – y = SQUARE(num)。 is expanded to y = num * num。 ? Advantage: since the data type of the argument is not specified, the macro can be used with any data type argument ? Be careful: val = SQUARE(num1 + num2)。 is expanded to val = num1 + num2 * num1 + num2。 ? Solution: use define SQUARE(x) (x) * (x) A First Book of ANSI C, Fourth Edition 33 Macros (continued) ? Macros are extremely useful when the calculations or expressions they contain are relatively simple ? A macro definition can be continued on a new line by using a \ ? The advantage of using a macro instead of a function is an increase in execution speed – No execution time loss due to the call and return procedures required by a function ? Disadvantage: the increase in required program memory space when a macro is used repeatedly – Each time a macro is used, the plete macro text is reproduced and stored as part of the program – A function is stored in memory only once A First Book of ANSI C, Fourth Edition 34 CommandLine Arguments A First B