Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the C++ equivalent of UINT32_MAX?

Tags:

c++

types

c99

In C99, I include stdint.h and that gives me UINT32_MAX as well as uint32_t data type. However, in C++ the UINT32_MAX gets defined out. I can define __STDC_LIMIT_MACROS before including stdint.h, but this does not work if someone is including my header after already including stdint.h themselves.

So in C++, what is the standard way of finding out the maximum value representable in a uint32_t?

like image 255
kdt Avatar asked Sep 24 '09 12:09

kdt


People also ask

What is UInt32 in C?

In C#, UInt32 struct is used to represent 32-bit unsigned integers(also termed as uint data type) starting from range 0 to 4,294,967,295.

What is max value of UInt32?

UInt32 Member Details. Represents the largest possible value of UInt32. This field is constant. The value of this constant is 4,294,967,295; that is, hexadecimal 0xFFFFFFFF.

What is the max value of double in C++?

The value of this constant is positive 1.7976931348623157E+308.


2 Answers

Not sure about uint32_t, but for fundamental types (bool, char, signed char, unsigned char, wchar_t, short, unsigned short, int, unsigned int, long, unsigned long, float, double and long double) you can use the numeric_limits templates via #include <limits>.

cout << "Minimum value for int: " << numeric_limits<int>::min() << endl; cout << "Maximum value for int: " << numeric_limits<int>::max() << endl; 

If uint32_t is a #define of one of the above than this code should work out of the box

cout << "Maximum value for uint32_t: " << numeric_limits<uint32_t>::max() << endl; 
like image 191
Glen Avatar answered Oct 02 '22 23:10

Glen


std::numeric_limits<T>::max() defines the maximum value for type T.

like image 25
Pete Kirkham Avatar answered Oct 02 '22 23:10

Pete Kirkham