Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 20 Nov 2012 06:31:12 -0600 Message-ID: <50AB7811.7712@mindspring.com> Date: Tue, 20 Nov 2012 07:31:13 -0500 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: time References: <4hjla8hdbe4ft1vjnnv6ppdqd08odelkbg@4ax.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 53 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.220.125 X-Trace: sv3-W97Rzgz5x5GBVFCHuOneuh+Uw1yjGAtodcUWr7zTnE+GHvgikWtskVCoMs2ZihcnWAUzzONY125gk5e!q6LEocp6BfagjSKd2VgjGoHZeLfTdOQEBFJiiEzpzKpK7bjrDfhVjWBP926l3PETOc59fwBGX7ch!LnS9X87e3s8= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3289 Xref: csiph.com comp.lang.c:28462 Keith Thompson wrote: > > "Bill Cunningham" writes: > > Keith Thompson wrote: > >> Geoff writes: > >>> On Mon, 19 Nov 2012 19:11:41 -0500, "Bill Cunningham" > >>> wrote: > >>>> I am using the time and date in my code using asctime () time(), > >>>> and localtime(). I know in POSIX they are obsolete but I am > >>>> concerned with c89-99. strftime() is suppoed to be the function > >>>> used now. I get the time and date just fine with the code I've > >>>> written but I want to use the time to seed a random number > >>>> generator. I don't know if I want seconds from epoch or what. Any > >>>> input? > >>> > >>> srand((unsigned)time(NULL)); > >> > >> The cast is unnecessary. time() returns a value of type time_t, > >> which is an arithmetic type; it will be implicitly converted to > >> the appropriate type for the argument to srand() (which, yes, > >> happens to be unsigned int). > > [snip] > > > > An arithmetic type? So what are you trying to say exactly in simple terms? > > This is an example of where I can pick up knowledge. Are you saying with > > "arithmetic types" casts aren't necessaary? > > An arithmetic type is either an integer type or a floating-point > type (or a complex or imaginary type, but don't worry about those). > N1570 6.2.5p18. > > If you assign a value of any arithmetic type to an object of > any arithmetic type (or initialize it, or pass it as a function > argument), the value will be implicitly converted to the target type. > N1570 6.5.16.1p1, first bullet. There are also implicit conversions > for other kinds of expressions, with more complicated rules; such > conversions *usually* do the right thing, but sometimes you might > need a cast to enforce a particular conversion. The condition of "*usually* do the right thing" also exists for arithmetic to arithmetic conversions. n1570 6.3 Conversions 6.3.1.4 Real floating and integer 1 If the value of the integral part cannot be represented by the integer type, the behavior is undefined. -- pete