开发者

using a portable int [duplicate]

开发者 https://www.devze.com 2022-12-16 09:39 出处:网络
This question already has answers here: C99 stdint.h header and MS Visual Studio (7 answers) Closed 9 years ago.
This question already has answers here: C99 stdint.h header and MS Visual Studio (7 answers) Closed 9 years ago.

gcc c99 MS2005/2008

I have started program that will be compiled on linux/windows.

The program will be compiled on linux using gcc 4.4.1 c99. And on windows the compiler will be either MS 2005/2008. And thi开发者_开发百科s I cannot change.

I am using SCons to create the build files. However, the reason I choose c99 as I can use the stdint.h so my integers would be compatible between different architectures i.e. x86_32 and 64 bit. using int32_t so it will compile without any problem on both 32 and 64 bit machines.

However, I have just discovered that c99 isn't used for ms compilers. Only c89. However, c89 doesn't have the stdint.t.

I am wondering what is the best way to make the integer portable among different compilers running on either 32 or 64.

Many thanks for any advice,


If you're not actually trying to directly map a binary format "from the wire", then you probably don't really need a fixed-width type at all.

By way of example, if you're using int32_t just because you need an integer than can store all values in the range -2147483647 to 2147483647, then a simple long is perfectly portable for that application - it is guaranteed to be at least that wide.

People seem to be inordinately keen on exact-width types.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号