Difference between different integer types

I was wondering what is the difference between uint32_t and uint32 , and when I looked in the header files, it had the following:

 types.h: /** @brief 32-bit unsigned integer. */ typedef unsigned int uint32; stdint.h: typedef unsigned uint32_t; 

This only leads to more questions: What is the difference between

 unsigned varName; 

and

 unsigned int varName; 

?

I am using MinGW.

+20
c ++ c
Aug 02 2018-12-21T00:
source share
4 answers

unsigned and unsigned int are synonyms very similar to [unsigned] short [int] and [unsigned] long [int] .

uint32_t is a type that (optionally) is defined by the C. standard. uint32 is just the name you created, although it is defined as the same thing.

+19
Aug 2 2018-12-12T00:
source share

There is no difference.

unsigned int = uint32 = uint32_t = unsigned in your case and unsigned int = unsigned always

+5
Aug 02 2018-12-12T00:
source share

There is absolutely no difference between unsigned and unsigned int .

Whether this type is a good match for uint32_t is implementation dependent; a int may be shorter than 32 bits.

+2
Aug 02 2018-12-12T00:
source share

unsigned and unsigned int are synonyms for historical reasons; they both mean "an unsigned integer of the most natural size for a CPU architecture / platform", which often (but by no means always) is 32 bits on modern platforms.

<stdint.h> is the standard C99 header that should give type definitions for integers of specific sizes, with the uint32_t symbol.

<types.h> that you are viewing looks non-standard and, presumably, belongs to some structure used by your project. Its uint32 typedef is compatible with uint32_t . If you must use one or another code, this is a question for your manager.

+1
Aug 02 '12 at 21:40
source share



All Articles