Presumably because your machine has enough memory to ensure the malloc() call succeeds. If the malloc() call failed -- and it can fail if there isn't enough free memory -- you will have all sorts of problems. That's one reason why most people terminate if malloc() returns NULL.Quote:
Originally Posted by Lionmane
The other related factor is that the range of integers supported on your machine (represented by macros like INT_MAX) is presumably large enough to be able to represent values within the range you're working in.
That is the result of what values can be represented in an int, and what can be represented in a double. An int is typically 4 bytes, and a double is typically 8. Depending on how the two types are implemented (by your compiler, which may do it based on how your operating system does it, which [in turn] may do it based on how your hardware does it), it is not impossible that every possible value that can be represented in an int can be represented precisely in a double ON YOUR MACHINE. As the range of values that can be represented in an int and a double are implementation dependent, it is also quite possible the conversion from double to int will lose information on another machine. It is also possible (in fact, likely in practice) that it will lose information for large values but not for small ones. That is what your compiler is warning you about.Quote:
Originally Posted by Lionmane
A warning is just that: a warning about something which MIGHT happen if the circumstances are right. The typecast does not make the possible loss of precision go way - it just stops the compiler compiler warning about it (as a typecast is essentially an instruction to the compiler of "I know what I'm doing; don't complain about this".Quote:
Originally Posted by Lionmane
Incidentally, rather than using "pow(count, 2)", why not use "count*count" or (if the resultant value may be larger than can be stored in an int), use "(long)count*count"?