Pelles C forum

C language => Expert questions => Topic started by: czerny on February 17, 2012, 07:18:49 PM

Title: Why long long
Post by: czerny 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
Title: Re: Why long long
Post by: CommonTater on February 17, 2012, 08:03:30 PM
I think we need a little more detail...   Converted where?

Title: Re: Why long long
Post by: czerny on February 17, 2012, 08:06:33 PM

#include <stdio.h>

int main(void)
{
if ((-2147483648 & 0xffffffff) > 0)     printf("positive\n");

return 0;

}


or try to print it. The compiler wants %llx


#include <stdio.h>

int main(void)
{
printf("%llx\n",-2147483648);

return 0;

}


czerny
Title: Re: Why long long
Post by: CommonTater 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.

#include <stdio.h>

int main(void)
{
printf("%d\n",-2147483648);
printf("%u\n",-2147483648);
printf("%x\n",-2147483648);
printf("%llx\n",-2147483648);

return 0;
}
Title: Re: Why long long
Post by: czerny on February 20, 2012, 02:34:11 PM
QuoteIt might be trying to prevent an overflow.

???

czerny