兼容性Compatibility

通用 C 运行库 (UCRT) 支持 c + + 一致性所需的大多数 C 标准库。The Universal C Runtime Library (UCRT) supports most of the C standard library required for C++ conformance. 它实现 C99 (ISO/IEC 9899:1999) 库,但有一些例外情况:It implements the C99 (ISO/IEC 9899:1999) library, with certain exceptions:

  • 中的 strict 类型兼容性 <complex.h> 。strict type compatibility in <complex.h>.
  • aligned_alloc,这可能不会实现,因为 Windows 操作系统不支持对齐分配。aligned_alloc, which will probably not be implemented because the Windows operating system doesn't support aligned allocations. 改为使用非标准的 _aligned_mallocUse the non-standard _aligned_malloc, instead.
  • strerrorlen_s
  • 中的原子支持 <stdatomic.h>atomic support in <stdatomic.h>
  • 线程支持 <threads.h>threading support in <threads.h>

UCRT 还实现了 POSIX (ISO/IEC 9945-1:1996,POSIX 系统应用程序编程接口) C 库的大型子集。The UCRT also implements a large subset of the POSIX.1 (ISO/IEC 9945-1:1996, the POSIX System Application Program Interface) C library. 但是,它并不完全符合任何特定的 POSIX 标准。However, it's not fully conformant to any specific POSIX standard. UCRT 还实现了几个特定于 Microsoft 的函数和不属于标准的宏。The UCRT also implements several Microsoft-specific functions and macros that aren't 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 can't 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 函数和 Microsoft 特定的运行时库函数都在全局命名空间中,但不属于标准 C 运行时库。Both the POSIX functions and Microsoft-specific runtime library functions are in the global namespace, but aren't part of the standard C runtime library. 这就是为什么这些函数的首选 Microsoft 实现具有前导下划线的原因。That's why the preferred Microsoft implementations of these functions have a leading underscore. 为了便于移植,UCRT 还支持默认名称,但使用它们编译代码时,Microsoft C++ 编译器会发出弃用警告。For portability, the UCRT also supports the default names, but the Microsoft C++ compiler issues a deprecation warning when code that uses them is compiled. 只会弃用默认名称,而不会弃用函数本身。Only the default names are deprecated, not the functions themselves. 若要取消警告,在使用原始 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. 当在运行时检测到问题时,它们将调用无效参数处理程序。They invoke the invalid parameter handler when an issue is detected at runtime. 默认情况下,如果使用的函数具有更加安全的变体,Microsoft C++ 编译器会发出弃用警告。By default, the Microsoft 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 macro enables 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. 有关详细信息,请参阅 CRT 中的安全功能For 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 应用商店或通用 Windows 平台 (UWP) 应用中不支持某些功能。Certain functions aren't supported in Windows Store or Universal Windows Platform (UWP) apps. 通用 Windows 平台应用中不支持的 CRT 函数中列出了这些函数。These functions are listed in CRT functions not supported in Universal Windows Platform apps.

TitleTitle 说明Description
UWP 应用、Windows 运行时和 C 运行时UWP Apps, the Windows Runtime, and the C runtime 说明 UCRT 例程何时与通用 Windows 应用或 Microsoft Store 应用不兼容。Describes when UCRT routines aren't compatible with Universal Windows apps or Microsoft 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.