How do I set a UInt32 to it's maximum value

Aran Mulholland picture Aran Mulholland · Nov 19, 2013 · Viewed 93.2k times · Source
  1. What is the maximum value for a UInt32?

  2. Is there a way I can use the sizeof operator to get the maximum value (as it is unsigned)? So I don't end up with #defines or magic numbers in my code.

Answer

CouchDeveloper picture CouchDeveloper · Nov 19, 2013

There's a macro UINT32_MAX defined in stdint.h which you can use

#include <stdint.h>

uint32_t max = UINT32_MAX;

More about the relevant header <stdint.h>:

http://pubs.opengroup.org/onlinepubs/009695299/basedefs/stdint.h.html