[cfe-dev] MS 128-bit literals don't always have the correct type
Dmitri Gribenko
gribozavr at gmail.com
Mon Sep 24 06:26:49 PDT 2012
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);
}
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the cfe-dev
mailing list