" Uint32 ", " int16 "等等;他们是标准c++吗?

时间:2020-12-22 16:27:53

I'm quite new to c++, but I've got the hang of the fundamentals. I've come across the use of "Uint32" (in various capitalizations) and similar data types when reading other's code, but I can't find any documentation mentioning them. I understand that "Uint32" is an unsigned int with 32 bits, but my compiler doesn't. I'm using visual c++ express, and it doesn't recognize any form of it from what I can tell.

我对c++很陌生,但是我掌握了基本原理。我在阅读别人的代码时遇到过“Uint32”(在各种大写形式中)和类似的数据类型的使用,但是我找不到任何文档提到它们。我知道“Uint32”是一个32位的无符号整数,但是我的编译器没有。我使用的是visual c++ express,它无法从我所能识别的信息中识别出它的任何形式。

Is there some compilers that reads those data types by default, or have these programmers declared them themselves as classes or #define constants?

是否有一些编译器默认读取这些数据类型,或者让这些程序员将它们声明为类或#define常量?

I can see a point in using them to know exactly how long your integer will be, since the normal declaration seems to vary depending on the system. Is there any other pros or cons using them?

我可以看到使用它们来精确地知道您的整数的长度,因为正常的声明似乎根据系统的不同而变化。还有其他的赞成或反对意见吗?

6 个解决方案

#1


12  

Visual c++ doesn't support the fixed-width integer types, because it doesn't include support for C99. Check out the answers to my question on this subject for various options you have for using them.

Visual c++不支持固定宽度的整数类型,因为它不支持C99。看看我关于这个问题的答案,你有各种选择来使用它们。

#2


19  

Unix platforms define these types in stdint.h, this is the preferred method of ensuring type sizing when writing portable code.

Unix平台在stdint中定义了这些类型。h,这是在编写可移植代码时确保类型大小的首选方法。

Microsoft's platforms do not define this header, which is a problem when going cross-platform. If you're not using Boost Integer Library already, I recommend getting Paul Hsieh's portable stdint.h implementation of this header for use on Microsoft platforms.

微软的平台没有定义这个标题,这是跨平台的问题。如果您还没有使用Boost Integer类库,我建议您使用Paul Hsieh的便携式stdint。h此头文件的实现,在微软平台上使用。

Update: Visual Studio 2010 and later do define this header.

更新:Visual Studio 2010,稍后将定义此标题。

#3


13  

The C99 header file stdint.h defines typedefs of this nature of the form uint32_t. As far as I know, standard C++ doesn't provide a cstdint version of this with the symbols in namespace std, but some compilers may, and you will typically be able to include the C99 header from C++ code anyways. The next version of C++ will provide the cstdint header.

C99头文件stdint。h定义了uint32_t形式的这种性质的typedef。据我所知,标准c++并没有提供cstdint版本的名称空间std中的符号,但是有些编译器可能会提供,而且您通常也能够包含来自c++代码的C99头。下一个c++版本将提供cstdint头。

You will often see code from other people who use non-standard forms of this theme, such as Uint32_t or Uint32 or uint32 etc. They typically just provide a single header that defines these types within the project. Probably this code was originally developed a long time ago, and they never bothered to sed replace the definitions out when C99 compilers became common.

您经常会看到使用此主题的非标准形式的其他人的代码,比如Uint32_t、Uint32或Uint32等等。它们通常只提供一个头,在项目中定义这些类型。可能这段代码最初是在很久以前开发的,当C99编译器变得普遍时,他们从来不会费心替换这些定义。

#4


3  

The main reason for using them is that you then don't have to worry about any possible problems arising when switching between 64bit and 32bit OS.

使用它们的主要原因是您不必担心在64位操作系统和32位操作系统之间切换时可能出现的任何问题。

Also if you are interfacing to any legacy code that you new was destined for 32bit or even 16bit then it avoids potential problems there as well.

此外,如果您正在与您新创建的任何遗留代码进行交互,那么它注定要使用32位甚至16位,那么它也避免了潜在的问题。

#5


1  

Try UINT32 for Microsoft.

尝试UINT32微软。

The upper case makes it clear that this is defined as a macro. If you try to compile using a different compiler that doesn't already contain the macro, you can define it yourself and your code doesn't have to change.

上面的大小写清楚地表明这是一个宏。如果您试图使用不包含宏的不同编译器编译,那么您可以自己定义它,您的代码也不必更改。

#6


1  

uint32 et al. are defined by macros. They solve a historic portability problem of there being few guarantees across platforms (back when there there more platform options than now) of how many bits you'd get when you asked for an int or a short. (One now-defunct C compile for the Mac provided 8-bit shorts!).

uint32等由宏定义。它们解决了一个具有历史意义的可移植性问题,即在不同平台之间(以前有比现在更多的平台选项)几乎没有什么保证,当您请求int或short时,您将得到多少位。(一个现在已经不存在的Mac C编译提供了8位的短路!)

#1


12  

Visual c++ doesn't support the fixed-width integer types, because it doesn't include support for C99. Check out the answers to my question on this subject for various options you have for using them.

Visual c++不支持固定宽度的整数类型,因为它不支持C99。看看我关于这个问题的答案,你有各种选择来使用它们。

#2


19  

Unix platforms define these types in stdint.h, this is the preferred method of ensuring type sizing when writing portable code.

Unix平台在stdint中定义了这些类型。h,这是在编写可移植代码时确保类型大小的首选方法。

Microsoft's platforms do not define this header, which is a problem when going cross-platform. If you're not using Boost Integer Library already, I recommend getting Paul Hsieh's portable stdint.h implementation of this header for use on Microsoft platforms.

微软的平台没有定义这个标题,这是跨平台的问题。如果您还没有使用Boost Integer类库,我建议您使用Paul Hsieh的便携式stdint。h此头文件的实现,在微软平台上使用。

Update: Visual Studio 2010 and later do define this header.

更新:Visual Studio 2010,稍后将定义此标题。

#3


13  

The C99 header file stdint.h defines typedefs of this nature of the form uint32_t. As far as I know, standard C++ doesn't provide a cstdint version of this with the symbols in namespace std, but some compilers may, and you will typically be able to include the C99 header from C++ code anyways. The next version of C++ will provide the cstdint header.

C99头文件stdint。h定义了uint32_t形式的这种性质的typedef。据我所知,标准c++并没有提供cstdint版本的名称空间std中的符号,但是有些编译器可能会提供,而且您通常也能够包含来自c++代码的C99头。下一个c++版本将提供cstdint头。

You will often see code from other people who use non-standard forms of this theme, such as Uint32_t or Uint32 or uint32 etc. They typically just provide a single header that defines these types within the project. Probably this code was originally developed a long time ago, and they never bothered to sed replace the definitions out when C99 compilers became common.

您经常会看到使用此主题的非标准形式的其他人的代码,比如Uint32_t、Uint32或Uint32等等。它们通常只提供一个头,在项目中定义这些类型。可能这段代码最初是在很久以前开发的,当C99编译器变得普遍时,他们从来不会费心替换这些定义。

#4


3  

The main reason for using them is that you then don't have to worry about any possible problems arising when switching between 64bit and 32bit OS.

使用它们的主要原因是您不必担心在64位操作系统和32位操作系统之间切换时可能出现的任何问题。

Also if you are interfacing to any legacy code that you new was destined for 32bit or even 16bit then it avoids potential problems there as well.

此外,如果您正在与您新创建的任何遗留代码进行交互,那么它注定要使用32位甚至16位,那么它也避免了潜在的问题。

#5


1  

Try UINT32 for Microsoft.

尝试UINT32微软。

The upper case makes it clear that this is defined as a macro. If you try to compile using a different compiler that doesn't already contain the macro, you can define it yourself and your code doesn't have to change.

上面的大小写清楚地表明这是一个宏。如果您试图使用不包含宏的不同编译器编译,那么您可以自己定义它,您的代码也不必更改。

#6


1  

uint32 et al. are defined by macros. They solve a historic portability problem of there being few guarantees across platforms (back when there there more platform options than now) of how many bits you'd get when you asked for an int or a short. (One now-defunct C compile for the Mac provided 8-bit shorts!).

uint32等由宏定义。它们解决了一个具有历史意义的可移植性问题,即在不同平台之间(以前有比现在更多的平台选项)几乎没有什么保证,当您请求int或short时,您将得到多少位。(一个现在已经不存在的Mac C编译提供了8位的短路!)