Possible loss of data?
Members - Reputation: 103
Posted 08 March 2005 - 11:52 AM
Staff Emeritus - Reputation: 1821
Posted 08 March 2005 - 11:56 AM
In this particular case, it doesn't matter - all you want is some unpredicatable value to start the random number generator with. If you want to silence the warning:
Members - Reputation: 850
Posted 08 March 2005 - 11:58 AM
In this case a loss of precision wouldn't cause any harm but in others it might, especially when writing portable code. The "solution" is to cast the return time into a basic integer.
srand((unsigned) time(0));The time_t type could correspond to any arithmetic type. And sending, for example, a floating point value to a function receiving an integer without explicitly casting it down is seen by the compiler as a potential source of bugs.
Members - Reputation: 3329
Posted 08 March 2005 - 12:00 PM
srand() takes an unsigned int.
The compiler is nice and auto-converts from time_t to unsigned int. The warning comes that a time_t isn't an unsigned int and has different maximums/minimums. So what happens if the time_t is greater than the unsigned int's maximum?