Thread: Measuring time

  1. #16
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    >>All I find...
    What you find has absolutely nothing to do with what the standard says.

    Here's how one would continue this argument:
    - Buy a copy of the standard.
    - Read it.
    - Assert your interpretations of the standard that support your argument.

    Otherwise, read the links provided in this thread and drawn your own conclusions. Here's mine: "If you don't care about portability or adhering to the standard, then do whatever works".


  2. #17
    Registered User
    Join Date
    Jun 2004
    Nothing to do with the standard??? Ok then maybe I've been posting MS specific code or something without knowing...
    But you still haven't presented that link to justify your opinion... Do that and I'll believe you.

    And I have a copy of the standard (pdf though). Let me quote it:
    typedef long time_t;
    I understand perfectly what you're saying but, I've never eared or readed anything about time_t not being arithmetic. There are non arithmetic types like struct tm.
    Last edited by xErath; 10-07-2004 at 09:11 AM.

  3. #18
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    >> Let me quote it:
    How bout a real qoute will some section numbers etc.
    Then what you'll want to do is explain how the quote supports your argument.


  4. #19
    Registered User
    Join Date
    Jun 2004
    I've done that, you didn't...
    Try looking in the time.h section

  5. #20
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Does the standard really define the implementation of the standard library functions? I was under the impression that it only defined the behaviour - in which case it is likely that the time.h that you are referring to (I'm assuming that you're looking at a header file and not an explicit statement of how the time_t must be defined) is only an example of how time.h might be implemented, and is not binding for those who wish to implement the standard in their own compilers.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #21
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Well, I usually try to teach folks how to fish, but some just need to be spoon fed…'s how you quote the standard:
    From: ISO/IEC 9899:1999 (E)
    7.23 Date and time <time.h>
    7.23.1 Components of time
        3 The types declared are size_t (described in 7.17);
          clock_t and time_t which are arithmetic types capable of representing 
          times; and struct tm which holds the components of a calendar time, 
          called the broken-down time.
    ... The time function
        1 #include <time.h>
          time_t time(time_t *timer);
        2 The time function determines the current calendar time. The encoding of 
          the value is unspecified.
        3 The time function returns the implementation’s best approximation to 
          the current calendar time. The value (time_t)(-1) is returned if the 
          calendar time is not available. If timer is not a null pointer, the 
          return value is also assigned to the object it points to.
    This is from C99 but applies equally to C89.

    There's a big difference between arithmetic properties (my original post) and an arithmetic type. The standard defines time_t as arithmetic type so that a comparison to (time_t)(-1) can be made. More importantly, the encoding of the time value is not defined. Meaning it could be seconds, micro-seconds, nano-seconds, or none of the above. The encoding doesn't even have to be in any unit of time, it could be a binary encoded decimal (BCD) of date/time values (adding 20 to a BCD doesn't make any sense).

    Under ISO C, time_t is an abstract type for which the only valid arithmetic operation is comparison to (time_t)(-1).

    As a side note, under the Single Unix Specification (the current POSIX standard), the time_t value returned by the time() function is defined to be in units of seconds. This is the most common implementation I've seen over the years.

    So, (once again) if you're not concerned with portability of source code under ISO C, simply follow the documentation that came with your standard C library implementation. As a contributor to these forums, I'm simply following the convention of pointing out what is standard and what isn't standard (as far as I understand it).

    I prefer "boo-yaa" over "busted"


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Execution Time - Rijandael encryption
    By gamer4life687 in forum C++ Programming
    Replies: 5
    Last Post: 09-20-2008, 09:25 PM
  2. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 03:41 AM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  4. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of
    Replies: 145
    Last Post: 04-09-2002, 06:17 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM