C++ __STDC_LIMIT_MACROS 和 __STDC_CONSTANT_MACROS 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/986426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 18:15:50  来源:igfitidea点击:

What do __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS mean?

c++stlmacros

提问by Matthew Willis

I see this in the standard C++ libraries for my system, as well as some of the headers in a library I'm using.

我在系统的标准 C++ 库以及我正在使用的库中的一些头文件中看到了这一点。

What are the semantics of these two definitions? Is there a good reference for #defines like this other than the source itself?

这两个定义的语义是什么?除了源本身之外,是否有像这样的#defines 的很​​好的参考?

回答by Dingo

__STDC_LIMIT_MACROSand __STDC_CONSTANT_MACROSare a workaround to allow C++ programs to use stdint.hmacros specified in the C99 standard that aren't in the C++ standard. The macros, such as UINT8_MAX, INT64_MIN, and INT32_C()may be defined already in C++ applications in other ways. To allow the user to decide if they want the macros defined as C99 does, many implementations require that __STDC_LIMIT_MACROSand __STDC_CONSTANT_MACROSbe defined before stdint.his included.

__STDC_LIMIT_MACROS并且__STDC_CONSTANT_MACROS是一种允许 C++ 程序使用stdint.hC99 标准中指定但不在 C++ 标准中的宏的变通方法。宏,例如UINT8_MAX, INT64_MIN, 和INT32_C()可能已经以其他方式在 C++ 应用程序中定义。为了让用户决定他们是否想要像 C99 那样定义的宏,许多实现都要求__STDC_LIMIT_MACROS__STDC_CONSTANT_MACROSstdint.h包含之前定义。

This isn't part of the C++ standard, but it has been adopted by more than one implementation.

这不是 C++ 标准的一部分,但它已被不止一个实现采用。

回答by malat

The above issue has vanished. C99 is an old standard, so this has been explicitly overruled in the C++11 standard, and as a consequence C11 has removed this rule.

上述问题已不复存在。C99 是一个旧标准,因此在 C++11 标准中已明确否决了这一点,因此 C11 已删除此规则。

More details there:

更多详情:

回答by laalto

In stdint.hunder C++, they control whether to define macros like INT32_MAXor INT32_C(v). See your platform's stdint.hfor additional information.

stdint.hC++ 下,它们控制是否定义宏,如INT32_MAXINT32_C(v)。有关stdint.h其他信息,请参阅您的平台。

回答by laalto

The macros are not part of the C++ standard and are probably used for internal purposes in your C++ implementation. If you want to know more about them, you should ask a question with atag that indicates what that implementation is.

宏不是 C++ 标准的一部分,可能在 C++ 实现中用于内部目的。如果您想了解更多关于它们的信息,您应该问一个带有 atag 的问题,表明该实现是什么。