Re: srand(time(NULL))
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Mon, 10 Mar 2008 11:51:01 -0400
Ioannis Vranos wrote:
The FAQ mentions:
#include <stdlib.h>
#include <time.h>
srand((unsigned int)time((time_t *)NULL));
I think the casting of NULL to "time_t *" is unnecessary in C, since NULL can be assigned to any pointer type without casting (also the conversion of void * to whatever_type * is implicit).
Also since the srand() function protype is
void srand(unsigned int seed);
I think the casting of the return value of time() to unsigned int is unnecessary, since the return value is implicitly converted to the unsigned int argument.
"Unnecessary" is not always the same as "undesirable" --
do you use indentation to indicate block nesting? -- and the
question of whether to use or omit these casts is in some
degree a matter of taste. Myself, I'd omit them. Yet the
Ten Commandments For C Programmers takes the opposite view
(Third Commandment), so I am probably in a state of sin.
--
Eric.Sosman@xxxxxxx
.
- Follow-Ups:
- Re: srand(time(NULL))
- From: Keith Thompson
- Re: srand(time(NULL))
- References:
- srand(time(NULL))
- From: Ioannis Vranos
- Re: srand(time(NULL))
- From: Mark Bluemel
- Re: srand(time(NULL))
- From: Ioannis Vranos
- srand(time(NULL))
- Prev by Date: Re: Backtick, at-sign, dollar-sign: legal in source?
- Next by Date: Re: which tutorial to use?
- Previous by thread: Re: srand(time(NULL))
- Next by thread: Re: srand(time(NULL))
- Index(es):
Relevant Pages
|