By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,388 Members | 1,839 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,388 IT Pros & Developers. It's quick & easy.

How to get 64-bit intermediate results

P: n/a
Hi,

If I'm doing something like this:

#include<stdint.h>

uint64_t i = (0xffff * 0xffff ) ;

Or indeed any arbitrarily long expression, how do I ensure the
intermediate results won't be truncated to 32 bits without putting
irritating (uint64_t) casts next to each operand? And how do I get a
default sizeof(int) == 8 on an IA-64/G5?
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

Richard Cavell wrote:
Hi,

If I'm doing something like this:

#include<stdint.h>

uint64_t i = (0xffff * 0xffff ) ;


Wrong group, ask in comp.lang.c
( This is C99, in comp.lang.c++ only C++98/C++2003 are on-topic
and they are not based on C99 )

Regards,
Michiel Salters

Jul 23 '05 #2

P: n/a
On 6/4/05 7:31 PM, msalters wrote:
Richard Cavell wrote:
Hi,

If I'm doing something like this:

#include<stdint.h>

uint64_t i = (0xffff * 0xffff ) ;

Wrong group, ask in comp.lang.c
( This is C99, in comp.lang.c++ only C++98/C++2003 are on-topic
and they are not based on C99 )


Okay, then what's the equivalent C++ way to do it?
Jul 23 '05 #3

P: n/a
Richard Cavell wrote:
Hi,

If I'm doing something like this:

#include<stdint.h>

uint64_t i = (0xffff * 0xffff ) ;

Or indeed any arbitrarily long expression, how do I ensure the
intermediate results won't be truncated to 32 bits without putting
irritating (uint64_t) casts next to each operand? And how do I get a
default sizeof(int) == 8 on an IA-64/G5?

If your question is about C, you should ask in comp.lang.c.
If your question is .NET related (Visual C++ .NET) you should ask in
microsoft.public.dotnet.languages.vc newsgroup.

If it doesn't appear in your news server use the public MS news server:

msnews.microsoft.com


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #4

P: n/a

Richard Cavell wrote:
On 6/4/05 7:31 PM, msalters wrote:
Richard Cavell wrote:
Hi,

If I'm doing something like this:

#include<stdint.h>

uint64_t i = (0xffff * 0xffff ) ;

Wrong group, ask in comp.lang.c
( This is C99, in comp.lang.c++ only C++98/C++2003 are on-topic
and they are not based on C99 )


Okay, then what's the equivalent C++ way to do it?


unsigned long i = (0xffffUL*0xffffUL);

which will not overflow, but I don't see what 64 bits code has to
do with it. Besides, IIRC math base 2^32 doesn't care about overflows
on multiplications. ~0UL*~0UL==01UL, even if I use a 64-bits
intermediate.

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.