C++ UInt8 和 uint8_t 有什么区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16937459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 20:46:19  来源:igfitidea点击:

Whats the difference between UInt8 and uint8_t

c++objective-cc

提问by user1845029

What is the differnce between UInt8and uint8_t, or UInt16and unit16_t?

之间是什么differnceUInt8uint8_t,或UInt16unit16_t

What does the _timply?

是什么意思_t

采纳答案by vdbuilder

In C99 the available basic integer types (the ones without _t) were deemed insufficient, because their actual sizes may vary across different systems.

在 C99 中,可用的基本整数类型(没有 _t 的那些)被认为是不够的,因为它们的实际大小可能因不同的系统而异。

So, the C99 standard includes definitions of several new integer types to enhance the portability of programs. The new types are especially useful in embedded environments.

因此,C99 标准包括几个新整数类型的定义,以增强程序的可移植性。新类型在嵌入式环境中特别有用。

All of the new types are suffixed with a _t and are guaranteed to be defined uniformly across all systems.

所有新类型都以 _t 为后缀,并保证在所有系统中统一定义。

For more info see the fixed-width integer types section of the wikipedia article on Stdint.

有关更多信息,请参阅有关 Stdint 的维基百科文章固定宽度整数类型部分

回答by PKS

normally they are used as a typedef datatypes. "_t" stand for a typedef datatype. we give such name so that they can be used and read easily across all the file or huge code base.

通常它们被用作 typedef 数据类型。“_t”代表 typedef 数据类型。我们给出这样的名称,以便它们可以在所有文件或庞大的代码库中轻松使用和阅读。

*UInt8 and uint8_t - Char*

*UInt8 和 uint8_t - 字符*

typedef unit8_t unsigned char

typedef unit8_t 无符号字符

*UInt16 and unit16_t*

*UInt16 和 unit16_t*

typedef unit16_t unsigned int( on a 16 bit compiler)

typedef unit16_t unsigned int(在 16 位编译器上)

回答by harald

The main difference is that the uintX_ttypes are standard C defined by C99 and later while UIntXis not. This has implications for how portable the code is. Code using uintX_ttypes can be compiled on any standard C compiler without any other dependencies. Code that uses UIntXon the other hand, must either define those types itself, or depend on some library or framework that does so.

主要区别在于uintX_t类型是由 C99 定义的标准 C,而后来UIntX则不是。这对代码的可移植性有影响。使用uintX_t类型的代码可以在任何标准 C 编译器上编译,而无需任何其他依赖项。UIntX另一方面,使用的代码必须要么自己定义这些类型,要么依赖于这样做的某个库或框架。

I don't think Objective-C as such defines any extra integer types, but it may well be that your framework (Coacoa, OpenStep?) does so. If your code makes no sense outside of the framework, use what's idiomatic in the framework context. Otherwise try to stick to the standard types.

我不认为 Objective-C 本身定义了任何额外的整数类型,但很可能是您的框架(Coacoa、OpenStep?)这样做了。如果您的代码在框架之外没有任何意义,请使用框架上下文中的惯用语。否则尝试坚持标准类型。