![](/img/trans.png)
[英]Do int8_t, int16_t, int32_t and int64_t have same respective ranges on different C++ compilers?
[英]Is there a standard macro in C or C++ represent the max and min value of int32_t, int64_t?
C或C ++中是否有任何宏表示int32_t和int64_t的最大值和最小值? 我知道它可以由字面上自己定义,但如果有一个标准的宏,它会更好。 请注意我不会询问最大的int,long等。 但是intXX_t
在C ++中, <limits>
标头中有std::numeric_limits::min()
和std::numeric_limits::max()
:
std::cout << std::numeric_limits<std::int32_t>::min() << std::endl;
等等。 在C中,头文件<stdint.h>
定义了INT32_MIN
, INT32_MAX
等。这些也可以在C ++ <cstdint>
头文件中找到。
在C ++中,您可以使用此标头中声明的标头<limits>
和类std::numeric_limts
。
要知道int32_t和int64_t类型的最大值和最小值,您可以编写例如
#include <cstdint>
#include <limits>
//...
std::cout << std::numeric_limits<int32_t>::max() << std::endl;
std::cout << std::numeric_limits<int32_t>::min() << std::endl;
std::cout << std::numeric_limits<int64_t>::max() << std::endl;
std::cout << std::numeric_limits<int64_t>::min() << std::endl;
在C中,您应该包含头<stdint.h>
并使用标头中定义的相应宏作为示例
INT32_MIN
INT32_MAX
INT64_MIN
INT64_MAX
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.