简体   繁体   English

从int转换为int32

[英]Convert from int to int32

I have a bunch of int's in my c++ code that I need to change to int32's. 我的c ++代码中有一堆int,我需要更改为int32。 Same with my bool's. 和我的布尔相同。 What header do I need to include in order to use int32's and bool32's. 为了使用int32和bool32,我需要包含哪个头。 Also how do I declare these once I make them. 一旦我制作它们,我该如何声明它们。 Am I able to just replace the int's with int32's? 我能用int32替换int吗?

For example: 例如:

int x;

Becomes

int32 x;

I am getting lots of errors when I try to change from int to int32. 当我尝试从int更改为int32时,我遇到了很多错误。 Here's a few: 这里有几个:

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2086: 'const int x' : redefinition

<cstdint>

If your compiler supports it, will get you int32_t, the C99 fixed width integer type. 如果您的编译器支持它,将获得int32_t,C99固定宽度整数类型。

Never heard of no bool32 and I can't imagine what kind of sense it would even make. 从来没有听说过没有bool32,我无法想象它甚至会产生什么样的感觉。

Yes, you can just replace int with your type so long as your type remains fundamental and/or has a default constructor/non-implicit constructor...depending on use. 是的,只要你的类型保持基础并且/或者有一个默认的构造函数/非隐式构造函数......你可以只用你的类型替换int ...取决于用途。

It might be better to have a typedef in place of the actual data type. 使用typedef代替实际数据类型可能会更好。

Eg 例如

typedef int my_int;
....
my_int var;

Becomes: 变为:

typedef int32 my_int;
....
my_int var;

That way, you could just change one line of code to change all instances of int to int32. 这样,您只需更改一行代码即可将int的所有实例更改为int32。

On windows you should be able to use the built in type __int32. 在Windows上,您应该能够使用内置类型__int32。 I've never hear of a 32 bit bool, but you can just use typedef for that one. 我从来没有听说过32位bool,但是你可以使用typedef。

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

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