public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* 64 bit assignment trouble on a 32 bit platform
@ 2007-10-29  9:37 kum
  2007-10-29 10:01 ` Samuel Tardieu
  2007-10-29 10:40 ` Rask Ingemann Lambertsen
  0 siblings, 2 replies; 3+ messages in thread
From: kum @ 2007-10-29  9:37 UTC (permalink / raw)
  To: gcc

hi,

UINT64 a64; // UINT64 has been typedefed as long long unsigned int
UINT32 a32, b32;
a32 = x; // some value
b32 = y; // some value

a64 = a32 * b32;
a64 += a32 + b32;

Is it necessary to type-cast both a32 and b32 to make above statements
to work as expected? Without casting, I find that addition works while
the multiplication does not. Is there a compiler option to make this
work without casting? I am using gcc 4.1.1 on an xscale platform.

Thanks,
kumaresh

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: 64 bit assignment trouble on a 32 bit platform
  2007-10-29  9:37 64 bit assignment trouble on a 32 bit platform kum
@ 2007-10-29 10:01 ` Samuel Tardieu
  2007-10-29 10:40 ` Rask Ingemann Lambertsen
  1 sibling, 0 replies; 3+ messages in thread
From: Samuel Tardieu @ 2007-10-29 10:01 UTC (permalink / raw)
  To: kum; +Cc: gcc

[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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: 64 bit assignment trouble on a 32 bit platform
  2007-10-29  9:37 64 bit assignment trouble on a 32 bit platform kum
  2007-10-29 10:01 ` Samuel Tardieu
@ 2007-10-29 10:40 ` Rask Ingemann Lambertsen
  1 sibling, 0 replies; 3+ messages in thread
From: Rask Ingemann Lambertsen @ 2007-10-29 10:40 UTC (permalink / raw)
  To: kum; +Cc: gcc

On Mon, Oct 29, 2007 at 03:05:32PM +0530, kum wrote:
> 
> Is it necessary to type-cast both a32 and b32 to make above statements
> to work as expected? Without casting, I find that addition works while
> the multiplication does not. Is there a compiler option to make this
> work without casting? I am using gcc 4.1.1 on an xscale platform.

   This is the wrong mailing list for such a question, please ask on
gcc-help@. Also please tell us what "work as expected" means. Otherwise, we
can't really answer your question.

-- 
Rask Ingemann Lambertsen
Danish law requires addresses in e-mail to be logged and stored for a year

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-10-29 10:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-29  9:37 64 bit assignment trouble on a 32 bit platform kum
2007-10-29 10:01 ` Samuel Tardieu
2007-10-29 10:40 ` Rask Ingemann Lambertsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).