【正文】
A First Book of ANSI C Fourth Edition Chapter 14 Additional Capabilities A First Book of ANSI C, Fourth Edition 2 Objectives ? Additional Features ? Bit Operations ? Macros ? CommandLine Arguments ? Common Programming and Compiler Errors A First Book of ANSI C, Fourth Edition 3 Additional Features ? The typedef declaration statement ? Conditional preprocessor directives ? Enumerated constants ? Conditional expressions ? The goto statement A First Book of ANSI C, Fourth Edition 4 The typedef Declaration Statement ? typedef permits constructing alternate names for an existing C data type name ? typedef double REAL。 makes the REAL an alias for double – REAL val。 is equivalent to double val。 ? typedef does not create a new data type ? The equivalence produced by typedef can frequently be produced equally well by define – typedef processed by the piler – define processed by the preprocessor A First Book of ANSI C, Fourth Edition 5 The typedef Declaration Statement (continued) ? Another example: typedef int ARRAY[100]。 ARRAY first, second。 ? Equivalent to the two definitions int first[100]。 and int second[100]。 ? As another example: typedef struct { char name[20]。 int idNum。 } empRecord。 empRecord employee[75]。 A First Book of ANSI C, Fourth Edition 6 Conditional Preprocessor Directives ? ifndef and ifdef permit conditional pilation in that the statements immediately following these directives, up to an else or endif, are piled only if the condition is true, whereas the statements following the else are piled only if the condition is false ? For example, ifndef condition pile the statements placed here else pile the statements placed here endif A First Book of ANSI C, Fourth Edition 7 Conditional Preprocessor Directives (continued) ? The else directive is optional ? ifndef is the most frequently used conditional preprocessor directive – Its most mon usage is in the form ifndef headerfile include headerfile endif – For example: ifndef include endif A First Book of ANSI C, Fourth Edition 8 Enumerated Constants ? Set of related integer values can be equated to an equivalent set of constants using an enumerated list – enum {Mon, Tue, Wed, Thr, Fri, Sat, Sun}。 ? By default, the first enumerated name in an enumerated list has a value of 0 ? The enumeration above is equivalent to: – define Mon 0 – define Tue 1 – define Wed 2 – … A First Book of ANSI C, Fourth Edition 9 Enumerated Constants (continued) ? To specify the value of the first enumerated name: – enum {Mon = 1, Tue, Wed, Thr, Fri, Sat, Sun}。 ? Any integer constant can be equated to enumerated names。 they need not be in