从 int 转换为 int32
我的 C++ 代码中有一堆 int,我需要将其更改为 int32。和我的布尔一样。为了使用 int32 和 bool32,我需要包含哪些标头。另外,一旦我制作了它们,我该如何声明它们。我可以用 int32 替换 int 吗?
例如:
int x;
当我尝试从 int 更改为 int32 时,我遇到
int32 x;
了很多错误。以下是一些:
错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int
error C2086: 'const int x' : redefinition
I have a bunch of int's in my c++ code that I need to change to int32's. Same with my bool's. What header do I need to include in order to use int32's and bool32's. Also how do I declare these once I make them. Am I able to just replace the int's with int32's?
For example:
int x;
Becomes
int32 x;
I am getting lots of errors when I try to change from int to 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你的编译器支持它,将会得到 int32_t,C99 固定宽度整数类型。
从来没有听说过 no bool32,我无法想象它会有什么样的意义。
是的,您可以将
int
替换为您的类型,只要您的类型保持基本类型和/或具有默认构造函数/非隐式构造函数...具体取决于使用情况。If your compiler supports it, will get you int32_t, the C99 fixed width integer type.
Never heard of no bool32 and I can't imagine what kind of sense it would even make.
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.在 Windows 上,您应该能够使用内置类型 __int32。我从来没有听说过 32 位 bool,但你可以使用 typedef 来实现它。
On windows you should be able to use the built in type __int32. I've never hear of a 32 bit bool, but you can just use typedef for that one.
使用
typedef
代替实际数据类型可能会更好。例如
:
这样,您只需更改一行代码即可将 int 的所有实例更改为 int32。
It might be better to have a
typedef
in place of the actual data type.E.g.
Becomes:
That way, you could just change one line of code to change all instances of int to int32.