[cfe-dev] MS 128-bit literals don't always have the correct type

Aaron Ballman aaron at aaronballman.com
Mon Sep 24 06:47:23 PDT 2012


On Mon, Sep 24, 2012 at 9:26 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> On Mon, Sep 24, 2012 at 4:15 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
>> On Mon, Sep 24, 2012 at 12:46 AM, Richard Smith <richard at metafoo.co.uk> wrote:
>>> Incidentally, we currently treat (for instance) 1000000000000000000i32 as a
>>> 64-bit integer. How does MSVC behave here? (Does i32 mean "this shall be an
>>> int32_t", or does it mean "this shall be *at least* an int32_t"?)
>>
>> It seems to mean that it shall be an int32_t.  In both 32- and 64-bit compiles.
>>
>> // 32-bit
>> ; 2    :   auto i = 1000000000000000000i32;
>>         mov     DWORD PTR _i$[ebp], -1486618624         ; a7640000H
>>
>> // 64-bit
>> ; 2    :   auto i = 1000000000000000000i32;
>>         mov     DWORD PTR i$[rsp], -1486618624          ; ffffffffa7640000H
>>
>> However, I can't find documentation on MSDN to suggest that this is
>> intended behavior or not.  The only integer type suffix documentation
>> they have lists i64, ll and LL (plus the u variants), but not i32.
>>
>> http://msdn.microsoft.com/en-us/library/00a1awxf(v=vs.110).aspx
>
> It would be more precise to ask the compiler itself, like:
>
> #include <type_traits>
> #include <iostream>
> #include <cstdint>
>
> template<typename T>
> void f(const T &t) {
>   std::cout << std::is_same<int, T>::value << " "
>             << std::is_same<long, T>::value << " "
>             << std::is_same<long long, T>::value << " "
>             << std::is_same<int32_t, T>::value << " "
>             << std::is_same<int64_t, T>::value << std::endl;
>   // also add 128-bit type here
> }
>
> int main() {
>   f(1i32);
>   f(0x100000000i32);
>   f(0x10000000000000000i32);
> }

1) VS does not accept 0x10000000000000000i32 as it claims the constant
size is too big.  It will only accept it as a decimal value.

2) All three tests return results consistent with the assembly posted:
1 0 0 1 0 (on both 32- and 64-bit builds)

~Aaron



More information about the cfe-dev mailing list