user1507133
user1507133

Reputation: 473

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 this:

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.

Upvotes: 27

Views: 26154

Answers (4)

RiaD
RiaD

Reputation: 47619

There is no difference.

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

Upvotes: 6

Kerrek SB
Kerrek SB

Reputation: 477010

unsigned and unsigned int are synonymous, much like unsigned short [int] and unsigned long [int].

uint32_t is a type that's (optionally) defined by the C standard. uint32 is just a name you made up, although it happens to be defined as the same thing.

Upvotes: 23

Russell Borogove
Russell Borogove

Reputation: 19037

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

<stdint.h> is a standard header in C99 that is supposed to give type definitions for integers of particular sizes, with the uint32_t naming convention.

The <types.h> that you're looking at appears to be non-standard and presumably belongs to some framework your project is using. Its uint32 typedef is compatible with uint32_t. Whether you should use one or the other in your code is a question for your manager.

Upvotes: 4

Mat
Mat

Reputation: 206689

There is absolutely no difference between unsigned and unsigned int.

Whether that type is a good match for uint32_t is implementation-dependant though; an int could be "shorter" than 32 bits.

Upvotes: 2

Related Questions