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
What do __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS mean?
提问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_MACROS
and __STDC_CONSTANT_MACROS
are a workaround to allow C++ programs to use stdint.h
macros 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_MACROS
and __STDC_CONSTANT_MACROS
be defined before stdint.h
is included.
__STDC_LIMIT_MACROS
并且__STDC_CONSTANT_MACROS
是一种允许 C++ 程序使用stdint.h
C99 标准中指定但不在 C++ 标准中的宏的变通方法。宏,例如UINT8_MAX
, INT64_MIN
, 和INT32_C()
可能已经以其他方式在 C++ 应用程序中定义。为了让用户决定他们是否想要像 C99 那样定义的宏,许多实现都要求__STDC_LIMIT_MACROS
并__STDC_CONSTANT_MACROS
在stdint.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.h
under C++, they control whether to define macros like INT32_MAX
or INT32_C(v)
. See your platform's stdint.h
for additional information.
在stdint.h
C++ 下,它们控制是否定义宏,如INT32_MAX
或INT32_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 的问题,表明该实现是什么。