-
You know, that's what std::size_t and std::ptrdiff_t are for. They're in <cstddef>.
On some systems, you can also find intptr_t and uintptr_t. They'd be in the C99 header <stdint.h>. Boost also provides them, I think, as boost::intptr_t and boost::uintptr_t in <boost/stdint.hpp>.
-
And, you can't get typedefs that depend on architecture with the preprocessor. Instead use this;
Code:
template<int bit_size> struct Helper
{
};
template<> struct Helper<16>
{
typedef int16_t intw;
typedef uint16_t uintw;
};
template<> struct Helper<32>
{
typedef int32_t intw;
typedef uint32_t uintw;
};
template<> struct Helper<64>
{
typedef int64_t intw;
typedef uint64_t uintw;
};
typedef Helper<sizeof(void *)*CHAR_BIT>::intw intw;
typedef Helper<sizeof(void *)*CHAR_BIT>::uintw uintw;
This, of course, relies on the types intXX_t and uintXX_t types being declared on your target system - which is not guaranteed either, IIRC.