NO

Author Topic: Why long long  (Read 3367 times)

czerny

  • Guest
Why long long
« on: February 17, 2012, 07:18:49 PM »
I have a little question:

The long -2147483648 could be represented by 0x80000000 and fit in 32 bits, but is convertet to long long by pelles c. Why?

czerny
« Last Edit: February 17, 2012, 08:31:10 PM by czerny »

CommonTater

  • Guest
Re: Why long long
« Reply #1 on: February 17, 2012, 08:03:30 PM »
I think we need a little more detail...   Converted where?


czerny

  • Guest
Re: Why long long
« Reply #2 on: February 17, 2012, 08:06:33 PM »
Code: [Select]
#include <stdio.h>
 
int main(void)
{
if ((-2147483648 & 0xffffffff) > 0)     printf("positive\n");

return 0;

}

or try to print it. The compiler wants %llx

Code: [Select]
#include <stdio.h>
 
int main(void)
{
printf("%llx\n",-2147483648);
 
return 0;

}

czerny
« Last Edit: February 17, 2012, 08:10:15 PM by czerny »

CommonTater

  • Guest
Re: Why long long
« Reply #3 on: February 17, 2012, 09:34:42 PM »
Try it with -2147483647  and see what it does...

It might be trying to prevent an overflow.
 
Code: [Select]
#include <stdio.h>
 
int main(void)
{
 printf("%d\n",-2147483648);
 printf("%u\n",-2147483648);
 printf("%x\n",-2147483648);
 printf("%llx\n",-2147483648);
 
 return 0;
}
« Last Edit: February 17, 2012, 09:40:36 PM by CommonTater »

czerny

  • Guest
Re: Why long long
« Reply #4 on: February 20, 2012, 02:34:11 PM »
Quote
It might be trying to prevent an overflow.

???

czerny