Convert from int to int32

孤人 提交于 2019-12-10 09:27:24

问题


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


回答1:


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.




回答2:


<cstdint>

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.




回答3:


It might be better to have a typedef in place of the actual data type.

E.g.

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.



来源:https://stackoverflow.com/questions/4854886/convert-from-int-to-int32

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!