94

Possible Duplicate:
Difference between different integer types

What is the difference between uint32 and uint32_t in C/C++?

Are they OS-dependent?

In which case should I use one or another?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Maxbester
  • 2,435
  • 7
  • 42
  • 70

2 Answers2

122

uint32_t is standard, uint32 is not. That is, if you include <inttypes.h> or <stdint.h>, you will get a definition of uint32_t. uint32 is a typedef in some local code base, but you should not expect it to exist unless you define it yourself. And defining it yourself is a bad idea.

William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • 15
    typedef uint32_t uint32? – bot47 Jun 22 '14 at 20:23
  • If it doesn't exist, you won't be able to compile your program, right? Then you could do like Max suggested above. What's the big deal about it? – Rodrigo May 14 '20 at 04:26
  • 2
    @Rodrigo The "big deal" is the same as doing `#define writef printf`. Technically, things will work just fine. But it introduces unnecessary confusion. And you'd be surprised how frequently you'll see simple typedefs like this morph over time until a code base has things like `typedef uint16_t uint32`, at which point the universe explodes. – William Pursell May 14 '20 at 16:23
  • Yes, I've dreamed of that already :) – Rodrigo May 14 '20 at 16:49
  • 1
    Why is `typedef uint32_t uint32` bad? Surely the argument that someone shouldn't use a sensible typedef because someone could create an insane typedef is wrong. Eg we don't say pencils are evil since a crazy coworker could take a pencil and stab someone with it. – Jason Harris Sep 29 '21 at 19:23
28

uint32_t is defined in the standard, in

18.4.1 Header <cstdint> synopsis [cstdint.syn]

namespace std {
//...
typedef unsigned integer type uint32_t; // optional
//...
}

uint32 is not, it's a shortcut provided by some compilers (probably as typedef uint32_t uint32) for ease of use.

Community
  • 1
  • 1
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625