Тип unsigned long отличается от uint32 _t и uint64 _t в Windows (VS2010)

В Visual Studio 2010 под 32-битной Windows 7 тип unsigned long, по-видимому, отличается как от uint32 _t, так и от uint64 _t. См. следующую тестовую программу:

#include <stdint.h>
#include <stdio.h>

template<class T, class U>
struct is_same_type
{
    static const bool value = false;
};
template<class T>
struct is_same_type<T, T>
{
    static const bool value = true;
};

#define TO_STRING(arg)        TO_STRING_IMPL(arg)
#define TO_STRING_IMPL(arg)   #arg

#define PRINT_SAME_TYPE(type1, type2) printf("%s (size=%d) %s %s (size=%d)\n", \
    TO_STRING(type1), int(sizeof(type1)), \
    is_same_type<type1, type2>::value ? "==" : "!=", \
    TO_STRING(type2), int(sizeof(type2)))


int main(int /*argc*/, const char* /*argv*/[])
{
    PRINT_SAME_TYPE(uint32_t, unsigned long);
    PRINT_SAME_TYPE(uint64_t, unsigned long);
    return 0;
}

Я ожидаю, что он напечатает либо

uint32_t (size=4) != unsigned long (size=8)
uint64_t (size=8) == unsigned long (size=8)

(который я получаю на x86 _64 Linux )или

uint32_t (size=4) == unsigned long (size=4)
uint64_t (size=8) != unsigned long (size=4)

при условии, конечно, что long не длиннее 64 бит.

Однако в Windows меня сбивает с толку

uint32_t (size=4) != unsigned long (size=4)
uint64_t (size=8) != unsigned long (size=4)

это означает, что существует два различных 32-битных беззнаковых типа. Разрешено ли это стандартом С++? Или это ошибка в компиляторе Visual C++?

6
задан James McNellis 23 July 2012 в 17:46
поделиться