I made a simple program that allows the user to pick a number of dice then guess the outcome... I posted this code before but with the wrong question so it was deleted... no
This line involves an implicit cast from time_t
which time
returns to unsigned int
which srand
takes:
srand ( time(NULL) );
You can make it an explicit cast instead:
srand ( static_cast<unsigned int>(time(NULL)) );
time()
returns a time_t
, which can be 32 or 64 bits. srand()
takes an unsigned int
, which is 32 bits. To be fair, you probably won't care since it's only being used as a seed for randomization.
That's because on your system, time_t
is a larger integer type than unsigned int
.
time()
returns a time_t
which is probably a 64-bit integer.srand()
wants an unsigned int
which is probably a 32-bit integer.Hence you get the warning. You can silence it with a cast:
srand ( (unsigned int)time(NULL) );
In this case, the downcast (and potential data loss) doesn't matter since you're only using it to seed the RNG.
This line involves an implicit cast from time_t which time returns to unsigned int which srand takes:
srand ( time(NULL) );
You can make it an explicit cast instead:
srand ( static_cast<unsigned int>(time(NULL)) );