Difference between uint32 and uint32_t [duplicate]
Asked Answered
E

2

99

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?

Epigenesis answered 13/11, 2012 at 14:1 Comment(4)
You should prefer Standard types wherever possible. In this case, uint32_t.Mellow
guys. You can find answer here: #11786613Ashien
Out of curiosity - what is the "_t" meant to indicate?Bhayani
Shorthand for "type".Intercede
H
126

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.

Hazing answered 13/11, 2012 at 14:2 Comment(5)
typedef uint32_t uint32?Sow
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?Hymie
@Hymie 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.Hazing
Yes, I've dreamed of that already :)Hymie
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.Duello
M
30

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.

Meir answered 13/11, 2012 at 14:3 Comment(2)
More likely as a typedef for something that was known to be an unsigned 32 bit integer at a time before <cstdint> was standard.Agram
But how could an "unsigned integer of 32 bits" be any different?Hymie

© 2022 - 2024 — McMap. All rights reserved.