兼容性Compatibility

通用 C 运行时库 (UCRT) 支持实现 C++ 一致性所需的大多数 C 标准库。The Universal C Run-Time Library (UCRT) supports most of the C standard library required for C++ conformance. 它实现了 C99 (ISO/IEC 9899:1999) 库,<tgmath.h> 中定义的泛型类型宏和 <complex.h> 中的严格的类型兼容性除外。It implements the C99 (ISO/IEC 9899:1999) library, with the exceptions of the type-generic macros defined in <tgmath.h>, and strict type compatibility in <complex.h>. UCRT 还实现了 POSIX.1(ISO/IEC 9945-1:1996,POSIX 系统应用程序编程接口)C 库的大型子集,但不完全符合任何特定的 POSIX 标准。The UCRT also implements a large subset of the POSIX.1 (ISO/IEC 9945-1:1996, the POSIX System Application Program Interface) C library, but is not fully conformant to any specific POSIX standard. 此外,UCRT 实现了几个特定于 Microsoft 的函数和不属于标准的一部分的宏。In addition, the UCRT implements several Microsoft-specific functions and macros that are not part of a standard.

在 vcruntime 库中找到了特定于 Visual C++ 的 Microsoft 实现的函数。Functions specific to the Microsoft implementation of Visual C++ are found in the vcruntime library. 这些函数中的许多函数都适用于内部使用,且不能通过用户代码调用。Many of these functions are for internal use and cannot be called by user code. 记录了一些函数,以供调试和实现兼容性时使用。Some are documented for use in debugging and implementation compatibility.

C++ 标准将全局命名空间中以下划线开头的名称保留到实现中。The C++ standard reserves names that begin with an underscore in the global namespace to the implementation. 因为 POSIX 函数位于全局命名空间中,但不属于标准 C 运行时库的一部分,所以这些函数特定于 Microsoft 的实现具有前导下划线。Because the POSIX functions are in the global namespace, but are not part of the standard C runtime library, the Microsoft-specific implementations of these functions have a leading underscore. 为了便于移植,UCRT 还支持默认名称,但是使用它们编译代码时,Visual C++ 编译器会发出弃用警告。For portability, the UCRT also supports the default names, but the Visual C++ compiler issues a deprecation warning when code that uses them is compiled. 仅会弃用默认的 POSIX 名称,而不会弃用函数。Only the default POSIX names are deprecated, not the functions. 若要取消警告,在使用原始 POSIX 名称的代码中包含任何标头之前,请定义 _CRT_NONSTDC_NO_WARNINGSTo suppress the warning, define _CRT_NONSTDC_NO_WARNINGS before including any headers in code that uses the original POSIX names.

由于误用参数和未检查缓冲区,标准 C 库中的某些函数具有不安全的使用情况历史记录。Certain functions in the standard C library have a history of unsafe usage, because of misused parameters and unchecked buffers. 这些函数通常是代码中出现的安全问题的来源。These functions are often the source of security issues in code. Microsoft 创建了这些函数的一组更加安全的版本,在运行时检测到问题时,可用于验证参数的使用情况并调用无效的参数处理程序。Microsoft created a set of safer versions of these functions that verify parameter usage and invoke the invalid parameter handler when an issue is detected at runtime. 默认情况下,如果使用的函数具有更加安全的变体,Visual C++ 编译器会发出弃用警告。By default, the Visual C++ compiler issues a deprecation warning when a function is used that has a safer variant available. 当编译 C++ 代码时,你可以将 _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 定义为 1,以消除大多数警告。When you compile your code as C++ , you can define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES as 1 to eliminate most warnings. 这会使用模板重载调用更加安全的变体,同时保持可移植的源代码。This uses template overloads to call the safer variants while maintaining portable source code. 若要取消警告,在使用这些函数的代码中包含任何标头之前,请定义 _CRT_SECURE_NO_WARNINGSTo suppress the warning, define _CRT_SECURE_NO_WARNINGS before including any headers in code that uses these functions. 有关详细信息,请参阅 Security Features in the CRTFor more information, see Security Features in the CRT.

除非文档中对特定函数另有注明,否则 UCRT 与 Windows API 可兼容。Except as noted within the documentation for specific functions, the UCRT is compatible with the Windows API. Windows 8 应用商店应用或 Windows 10 上的通用 Windows 应用中不支持某些函数。Certain functions are not supported in Windows 8 Store apps or in Universal Windows apps on Windows 10. 这些函数都列在 /ZW 不支持 CRT 函数中,其中枚举了 Windows 运行时不支持的函数。These functions are listed in CRT functions not supported with /ZW, which enumerates the functions not supported by the Windows Runtime.

标题Title 描述Description
Windows 应用商店应用程序、Windows 运行时和 C 运行时Windows Store Apps, the Windows Runtime, and the C Run-Time 说明 UCRT 例程何时与通用 Windows 应用或 Windows 应用商店应用不兼容。Describes when UCRT routines are not compatible with Universal Windows apps or Windows Store apps.
ANSI C 遵从性ANSI C Compliance 说明 UCRT 中符合标准的命名。Describes standard-compliant naming in the UCRT.
UNIXUNIX 提供将程序移植到 UNIX 的指南。Provides guidelines for porting programs to UNIX.
Windows 平台 (CRT)Windows Platforms (CRT) 列出 CRT 支持的操作系统。Lists the operating systems that are the CRT supports.
向后兼容性Backward Compatibility 描述如何将旧 CRT 名称映射到新名称。Describes how to map old CRT names to the new ones.
CRT 库功能CRT Library Features 提供 CRT 库 (.lib) 文件和关联的编译器选项的概述。Provides an overview of the CRT library (.lib) files and the associated compiler options.