Results 1 to 8 of 8

Thread: What are clock_t and time_t?

  1. #1
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default What are clock_t and time_t?

    In the description of time.h I have read that clock_t and time_t are arithmetic types representing times, but I do not understand what exact datatypes these are - how many bytes they hold, etc. For instance, if I have:
    Qt Code:
    1. #include <time.h>
    2. time_t now;
    3. now = time();
    To copy to clipboard, switch view to plain text mode 
    what formatting would I need to use if I use the variable now in a printf statement?
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What are clock_t and time_t?

    what exact datatypes these
    They are generally defined as long int.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What are clock_t and time_t?

    Quote Originally Posted by jamadagni
    how many bytes they hold
    This you can always find out using sizeof().

  4. #4
    Join Date
    Jan 2006
    Location
    Shanghai, China
    Posts
    52
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What are clock_t and time_t?

    Why not find it out yourself by looking into the header file?
    1. Users don't have the manual, and if they did, they wouldn't read it.
    2. In fact, users can't read anything, and if they could, they wouldn't want to.

  5. #5
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: What are clock_t and time_t?

    Quote Originally Posted by bood
    Why not find it out yourself by looking into the header file
    /usr/include/time.h did not have any useful info.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  6. #6
    Join Date
    Jan 2006
    Location
    Shanghai, China
    Posts
    52
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What are clock_t and time_t?

    Quote Originally Posted by jamadagni
    /usr/include/time.h did not have any useful info.
    Pretty weird...
    This from my gcc 3.4.3/mingw
    Qt Code:
    1. #ifndef _CLOCK_T_DEFINED
    2. typedef long clock_t;
    3. #define _CLOCK_T_DEFINED
    4. #endif
    5.  
    6. #ifndef _TIME_T_DEFINED
    7. typedef long time_t;
    8. #define _TIME_T_DEFINED
    9. #endif
    To copy to clipboard, switch view to plain text mode 

    And it seems from the standard that it's implemention dependent
    1. Users don't have the manual, and if they did, they wouldn't read it.
    2. In fact, users can't read anything, and if they could, they wouldn't want to.

  7. #7
    Join Date
    Jan 2006
    Location
    Lincoln, NE USA
    Posts
    177
    Thanks
    3
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What are clock_t and time_t?

    Quote Originally Posted by jamadagni
    /usr/include/time.h did not have any useful info.

    mmm... Here is what the time.h header included with MSVC++ 6.0 has:
    Qt Code:
    1. /* Define the implementation defined time type */
    2. #ifndef _TIME_T_DEFINED
    3. #ifdef _WIN64
    4. typedef __int64 time_t; /* time value */
    5. #else
    6. typedef _W64 long time_t; /* time value */
    7. #endif
    8. #define _TIME_T_DEFINED /* avoid multiple def's of time_t */
    9. #endif
    To copy to clipboard, switch view to plain text mode 
    That tells me exactly how time_t is defined.

  8. #8
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What are clock_t and time_t?

    __int64 is obviously a 64bit (implicitly signed) integer which in pure C++ (i.e. : not polluted by Microsoft) is called a "long long int" .


    edit:

    to learn more about _W64 check out the files included by your time.h
    Current Qt projects : QCodeEdit, RotiDeCode

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.