必需和可选的头文件Required and Optional Header Files

每个运行时例程的说明包括一个针对该例程的必选和可选包含文件或标头 (.H) 文件的列表。The description of each run-time routine includes a list of the required and optional include, or header (.H), files for that routine. 需包括必需的标头文件以获取此例程的函数声明或由另一个内部调用的例程使用的定义。Required header files need to be included to obtain the function declaration for the routine or a definition used by another routine called internally. 通常包括可选标头文件以利用预定义的常量、类型定义或内联宏。Optional header files are usually included to take advantage of predefined constants, type definitions, or inline macros. 下表列出了可选标头内容的一些示例:The following table lists some examples of optional header file contents:

定义Definition 示例Example
宏定义Macro definition 如果将库例程作为宏实现,则宏定义可能在原始例程的标头文件之外的其他标头文件中。If a library routine is implemented as a macro, the macro definition may be in a header file other than the header file for the original routine. 例如,在标头文件 CTYPE.H 中定义 _toupper 宏,而在 STDLIB.H 中声明函数 toupperFor instance, the _toupper macro is defined in the header file CTYPE.H, while the function toupper is declared in STDLIB.H.
预定义的常量Predefined Constant 许多库例程都引用在标头文件中定义的常量。Many library routines refer to constants that are defined in header files. 例如,_open 例程使用常量,如在标头文件 FCNTL.H 中定义的 _O_CREATFor instance, the _open routine uses constants such as _O_CREAT, which is defined in the header file FCNTL.H.
类型定义Type definition 某些库例程返回结构或将结构用作参数。Some library routines return a structure or take a structure as an argument. 例如,流输入/输出例程使用在 STDIO.H 中定义的 FILE 类型的结构。For example, stream input/output routines use a structure of type FILE, which is defined in STDIO.H.

运行库标头文件提供 ANSI/ISO C 标准推荐样式的函数声明。The run-time library header files provide function declarations in the ANSI/ISO C standard recommended style. 编译器对在其关联的函数声明后发生的任何例程引用执行类型检查。The compiler performs type checking on any routine reference that occurs after its associated function declaration. 函数声明对于返回默认的 int 类型之外的其他类型的值的例程尤为重要。Function declarations are especially important for routines that return a value of some type other than int, which is the default. 未在其声明中指定适当的返回值的例程将由编译器用来返回 int,这可能导致出现意外结果。Routines that do not specify their appropriate return value in their declaration will be considered by the compiler to return an int, which can cause unexpected results. 有关详细信息,请参阅类型检查See Type Checking for more information.

另请参阅See Also

CRT 库功能CRT Library Features