Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #28462

Re: time

Message-ID <50AB7811.7712@mindspring.com> (permalink)
Date 2012-11-20 07:31 -0500
From pete <pfiland@mindspring.com>
Organization PF
Newsgroups comp.lang.c
Subject Re: time
References <k8ehrs$ddf$1@dont-email.me> <4hjla8hdbe4ft1vjnnv6ppdqd08odelkbg@4ax.com> <lnd2z9f65y.fsf@nuthaus.mib.org> <k8el52$u6c$1@dont-email.me> <lnd2z8r9oe.fsf@nuthaus.mib.org>

Show all headers | View raw


Keith Thompson wrote:
> 
> "Bill Cunningham" <nospam@nspam.invalid> writes:
> > Keith Thompson wrote:
> >> Geoff <geoff@invalid.invalid> writes:
> >>> On Mon, 19 Nov 2012 19:11:41 -0500, "Bill Cunningham"
> >>> <nospam@nspam.invalid> 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

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

time "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-19 19:11 -0500
  Re: time Geoff <geoff@invalid.invalid> - 2012-11-19 16:26 -0800
    Re: time Keith Thompson <kst-u@mib.org> - 2012-11-19 16:51 -0800
      Re: time Geoff <geoff@invalid.invalid> - 2012-11-19 17:01 -0800
      Re: time "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-19 20:07 -0500
        Re: time Keith Thompson <kst-u@mib.org> - 2012-11-19 23:54 -0800
          Re: time pete <pfiland@mindspring.com> - 2012-11-20 07:31 -0500
          Re: time "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-20 17:09 -0500
  Re: time Keith Thompson <kst-u@mib.org> - 2012-11-19 16:30 -0800
    Re: time "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-19 20:04 -0500
      Re: time Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-25 05:52 -0800
  Re: time Nobody <nobody@nowhere.com> - 2012-11-20 03:07 +0000
    Re: time Keith Thompson <kst-u@mib.org> - 2012-11-19 23:58 -0800
    Re: time Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2012-11-21 08:30 -0800
      Re: time "osmium" <r124c4u102@comcast.net> - 2012-11-21 11:11 -0600
      Re: time James Kuyper <jameskuyper@verizon.net> - 2012-11-21 12:22 -0500
        Re: time gof@somewhere.invalid (Adam Wysocki) - 2012-11-21 19:09 +0000
          Re: time Keith Thompson <kst-u@mib.org> - 2012-11-21 12:01 -0800
            Re: time gof@somewhere.invalid (Adam Wysocki) - 2012-11-23 08:15 +0000
          Re: time "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-21 15:16 -0500
            Re: time "osmium" <r124c4u102@comcast.net> - 2012-11-21 14:23 -0600
              Re: time Rosario1903 <Rosario@invalid.invalid> - 2012-11-22 10:25 +0100
            Re: time Keith Thompson <kst-u@mib.org> - 2012-11-21 12:30 -0800
              Re: time "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-21 18:24 -0500
            Re: time Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-25 05:56 -0800
          Re: time Nobody <nobody@nowhere.com> - 2012-11-22 02:00 +0000
            Re: time Keith Thompson <kst-u@mib.org> - 2012-11-21 19:57 -0800
              Re: time gof@somewhere.invalid (Adam Wysocki) - 2012-11-23 08:31 +0000
            Re: time army1987 <army1987@ask-for-it.invalid> - 2012-11-24 13:58 +0000
          Re: time Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-11-22 11:36 +0000
            Re: time gof@somewhere.invalid (Adam Wysocki) - 2012-11-23 08:20 +0000
              Re: time Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-11-23 14:31 +0000
      Re: time Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-11-25 05:54 -0800
  Re: time Mark Storkamp <mstorkamp@yahoo.com> - 2012-11-20 08:34 -0600
    Re: time "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-20 20:37 -0500
      Re: time Keith Thompson <kst-u@mib.org> - 2012-11-20 20:25 -0800
        Re: time "Bill Cunningham" <nospam@nspam.invalid> - 2012-11-21 15:11 -0500

csiph-web