News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Why long long

Started by czerny, February 17, 2012, 07:18:49 PM

Previous topic - Next topic

czerny

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

CommonTater

I think we need a little more detail...   Converted where?


czerny

#2

#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

CommonTater

#3
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;
}

czerny

QuoteIt might be trying to prevent an overflow.

???

czerny