27

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.

3
  • 9
    They're the same. However the type uint32 (and the header <types.h> or the file "types.h") is not defined by the C99 Standard. If you want to use one of those types, use uint32_t and include the header <stdint.h>. Also unsigned and unsigned int are the same. Commented Aug 2, 2012 at 21:34
  • 1
    So uint32 and <types.h> are not part of the standard, but uint32_t is? Commented Aug 2, 2012 at 21:40
  • 2
    @user1507133: Yes. Basically, there's no such thing as uint32 neither in C nor in C++. Commented Aug 2, 2012 at 21:42

4 Answers 4

23

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.

Sign up to request clarification or add additional context in comments.

1 Comment

A bit of necromancy here, but comparing unsigned [int] to [unsigned] (short|long) [int] may give new programmers the false impression that short and long are unsigned by default. I'd suggest unsigned (short|long) [int] instead.
6

There is no difference.

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

3 Comments

unsigned int == unsigned, but it is not in any way guaranteed that uint32_t == unsigned int. unsigned int can have any bit-width from 16 bit and up.
In an environment with those particular typedefs, uint32_t is by definition unsigned int.
@AndreyT: that's why I wrote "in your case"
4

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.

4 Comments

"<stdint.h> is a standard header in C99". What about C++98 and C++11?
<cstdint> is, I think, the equivalent C++ standard header.
@user1507133 - C++11 has <cstdint> which brings these types into the std namespace (e.g. std::uint32_t). C++98 does not have this header because it predates C99. POSIX provides inttypes.h with the same types if that is good enough.
According to the C Standard, <inttypes.h> includes <stdint.h>. So it "copies" every definition and provides a few extra ones (notably scanf and printf specifiers: printf("%" PRIu32 "\n", x);
2

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.