I want to use U32 type but I can't find the header where it is defined. Does anyone know?
Asked
Active
Viewed 3.1k times
3 Answers
15
There is no standard type called U32
, but if you #include <cstdint>
(stdint.h
for C) you can use std::uint32_t
1, a 32 bit unsigned integer, which is (I assume) what you want.
Here is a list of types in the cstdint
header:
namespace std {
int8_t
int16_t
int32_t
int64_t
int_fast8_t
int_fast16_t
int_fast32_t
int_fast64_t
int_least8_t
int_least16_t
int_least32_t
int_least64_t
intmax_t
intptr_t
uint8_t
uint16_t
uint32_t
uint64_t
uint_fast8_t
uint_fast16_t
uint_fast32_t
uint_fast64_t
uint_least8_t
uint_least16_t
uint_least32_t
uint_least64_t
uintmax_t
uintptr_t
}
1 Thanks Martinho Fernandes for pointing out that these types are in the namespace std
.

anatolyg
- 26,506
- 9
- 60
- 134

Seth Carnegie
- 73,875
- 22
- 181
- 249
-
On "Game Engine Architecture" there a code sppinet that uses U32... thats why I'm asking... – Tiago Costa Aug 28 '11 at 00:25
-
@Tiago: You realize that C has the `typedef` keyword that lets you make type aliases? – Kerrek SB Aug 28 '11 at 00:26
-
1Note that the types in `
` are in namespace `std`. – R. Martinho Fernandes Aug 28 '11 at 01:19 -
I like style of u32/u64... , is there an off-shelf header file that defined these types ? many thank!!! – yushang Jan 15 '21 at 11:21
2
U32 is an idiomatic shortcut for an unsigned int. Its common definition is:
typedef unsigned int U32;
But the main reason for its use is to be able to control the actual definition manually. Hope this helps.

user46748
- 145
- 2
- 4
-
4`unsigned int` is not guaranteed to be 32 bits so such a typedef is just really bad. – ChrisWue Feb 09 '16 at 19:03
-
2
While cstdint might be a solution, it's not universal -- MSVC versions before 2010 didn't ship with that one. If writing for multiple platforms you'll need to supply the standard types yourself if MSVC < 2010 is detected. Or use the boost one if you use boost.

Kornel Kisielewicz
- 55,802
- 15
- 111
- 149