2011-04-14 44 views

回答

37

Visual C++ 2010包括<cstdint>,其中包括typedef std::int32_t(您也可以包含<stdint.h>,它在全局命名空間中具有相同的typedef)。

如果您使用的是舊版本的Visual C++,則可以使用Boost's <cstdint> implementation

1

int。但是,如果要在2010年之前的VC++版本(其中引入cstdint標頭)中繼續使用stdint typedefs,請考慮使用BoostConfigcstdint implementation

+0

我不是downvoter,但要注意,int32_t簽署。所以你可能應該說:'int',因爲它是VC上的32位。 – 2011-04-14 02:17:39

+0

我不相信你可以保證VC編譯的每個體系結構都有一個32位的int。 – user470379 2011-04-14 03:05:24

+0

@ user470379:由於VC++ 1.52,它實際上保證'int'是32位。如果你使用的是早期版本的VC++,那麼我懷疑你會比'sizeof(int)'更大的問題擔心; - ] – ildjarn 2011-04-14 03:44:13

7

如果您有預編碼的cstdint版本的Visual Studio,則可以使用__int32

8

我要做的就是讓我自己的typedef確保類型存在像這樣經過:

#ifdef _MSC_VER 
    #if _MSC_VER >= 1600 
     #include <cstdint> 
    #else 
     typedef __int8    int8_t; 
     typedef __int16    int16_t; 
     typedef __int32    int32_t; 
     typedef __int64    int64_t; 
     typedef unsigned __int8  uint8_t; 
     typedef unsigned __int16 uint16_t; 
     typedef unsigned __int32 uint32_t; 
     typedef unsigned __int64 uint64_t; 
    #endif 
#elif __GNUC__ >= 3 
    #include <cstdint> 
#endif 

typedef int8_t  s8; 
typedef int16_t  s16; 
typedef int32_t  s32; 
typedef int64_t  s64; 
typedef uint8_t  u8; 
typedef uint16_t u16; 
typedef uint32_t u32; 
typedef uint64_t u64; 
相關問題