简体   繁体   English

不同整数类型之间的差异

[英]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: 我想知道uint32_tuint32什么区别,当我查看头文件时它有这个:

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. 我正在使用MinGW.

unsigned and unsigned int are synonymous, much like unsigned short [int] and unsigned long [int] . unsignedunsigned int是同义词,非常类似于unsigned short [int]unsigned long [int]

uint32_t is a type that's (optionally) defined by the C standard. uint32_t是由C标准定义的(可选)类型。 uint32 is just a name you made up, although it happens to be defined as the same thing. uint32只是一个你组成的名字,虽然碰巧被定义为同一个东西。

There is no difference. 没有区别。

unsigned int = uint32 = uint32_t = unsigned in your case and unsigned int = unsigned always unsigned int = uint32 = uint32_t = unsigned在你的情况下是unsigned int = unsignedunsigned int = unsigned always

There is absolutely no difference between unsigned and unsigned int . unsignedunsigned int之间绝对没有区别。

Whether that type is a good match for uint32_t is implementation-dependant though; 该类型是否与uint32_t匹配良好但是依赖于实现; an int could be "shorter" than 32 bits. int可以比32位“更短”。

unsigned and unsigned int are synonymous for historical reasons; unsignedunsigned int是历史原因的同义词; 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. 它们都意味着“CPU架构/平台最自然大小的无符号整数”,这在现代平台上通常(但绝不总是)32位。

<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. <stdint.h>是C99中的标准头,它应该使用uint32_t命名约定为特定大小的整数提供类型定义。

The <types.h> that you're looking at appears to be non-standard and presumably belongs to some framework your project is using. 您正在查看的<types.h>似乎是非标准的,可能属于您的项目正在使用的某个框架。 Its uint32 typedef is compatible with uint32_t . 它的uint32 typedef与uint32_t兼容。 Whether you should use one or the other in your code is a question for your manager. 您是否应该在代码中使用其中一个是您的经理的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM