Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard macro in C or C++ represent the max and min value of int32_t, int64_t?

Tags:

c++

c

Is there any macro in C or C++ represent the max and min value of int32_t and int64_t? I know it can be literally defined by oneself, but it's better if there is a standard macro. Please note I'm not asking about max of int, long ,etc. but intXX_t

like image 554
xuhdev Avatar asked Dec 09 '22 02:12

xuhdev


2 Answers

In C++, there is std::numeric_limits::min() and std::numeric_limits::max() in the <limits> header:

std::cout << std::numeric_limits<std::int32_t>::min() << std::endl;

and so on. In C, the header <stdint.h> defines INT32_MIN, INT32_MAX etc. These are also available in the C++ <cstdint> header.

like image 139
juanchopanza Avatar answered Apr 28 '23 13:04

juanchopanza


In C++ you can use header <limits> and class std::numeric_limts declared in this header.

To know the max and min values of types int32_t and int64_t you can write for example

#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;

In C you should include header <stdint.h> and use corresponding macros defined in the header as for example

INT32_MIN
INT32_MAX
INT64_MIN
INT64_MAX
like image 22
Vlad from Moscow Avatar answered Apr 28 '23 12:04

Vlad from Moscow