I boot into Linux and use the u_int64_t or the unsigned long long as you mention. A bit more type casting would get the OP there I think. Or just use the routine you mentioned.
The definitions in xbasic_types.h are compiler independent. In other words, unfortunately, not all compilers support "unsigned long long". We also found that some of them do but the result of the computation was incorrect.
GCC does support "unsigned long long" and produces the correct result.
- Peter
Sylva>> You need to type cast test1 and test2 to be 64 bits before you
C does what's called "integral promotion" when doing a math operation. Basically, if you do some math with two types, the compiler chooses a type for the intermediate results. The simplified rule is: if the operand types fit in an int, use an int, otherwise use an unsigned int. Your multiply on the first line is going to have a 32 bit result on any
32-bit-int system. That means when you shift it down 32, you'll get 0.
The only way to get the compiler to do the math in a wider type is to explicitly force one of them to be wider. That's what all the casting is about in the other replies you've gotten. If it's not working, it's a flaw of your compiler. The PPC target of GCC could do what you want just fine.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.