c400-l-bounces+seurer=us.ibm.com@xxxxxxxxxxxx wrote on 06/01/2011 01:42:49
PM:

From: "Chris Hird" <chrish@xxxxxxxxxxxxxxxxx>

Thanks, I thought the cast would have told the compiler to reserve a
storage space for a double. I suppose because I added the .0 to
each of the values it know that they were floats/doubles?

However if I use the following it also gives an incorrect result.

Unsigned long long test = 0;

Test = (2482884 * 1024);
Printf("%llu\n",test);

I get 18446744071957057536 that is not wrapping but it certainly
gives me the wrong answer?? Why would that happen?

As Aaron noted when you multiply two ints (otherwise unmarked integral
constants are ints) the result is an int. So your expression:

Test = (2482884 * 1024);

is really done like this:

int __temp = (2482884 * 1024);
Test = (Unsigned long long) __temp;

No real temporary variables will be used but you get the idea.

You can mark the constants as unsigned long long by adding "ull" at the
end:

Test = (2482884ull * 1024ull);

--
Bill

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].