This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: 64 bit assignment trouble on a 32 bit platform
[this is not a question for the GCC developers list]
Kumaresh> Is it necessary to type-cast both a32 and b32 to make above
Kumaresh> statements to work as expected?
Yes.
Kumaresh> Without casting, I find that addition works while the
Kumaresh> multiplication does not.
Addition is not supposed to work either. I guess that your addition
just doesn't overflow the capacity of an UINT32 while your
multiplication does.
The following program shows it clearly:
#include <stdio.h>
typedef long long unsigned UINT64;
typedef long unsigned UINT32;
int main(void)
{
UINT32 a = 0xffffffff;
UINT32 b = a;
printf ("a+b = 0x%016llx\n", (UINT64) (a+b));
return 0;
}
The output will be:
a+b = 0x00000000fffffffe
instead of your expected
a+b = 0x00000001fffffffe
Sam
--
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/