Making a timer...

This is a discussion on Making a timer... within the C++ Programming forums, part of the General Programming Boards category; Checked and found that time_T pretty much has to be an integer. Most implementations will overrflow in the year 2038, ...

  1. #16
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Checked and found that time_T pretty much has to be an integer. Most implementations will overrflow in the year 2038, henceforth the type will most likely be 64-bit.

  2. #17
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Heh. The year 2038 bug.

    I would have thought they'd modify the start date for the clock mechanism to a newer date. Or better yet make a preprocessor that adds the current date when it compiles the compiler.

  3. #18
    Registered User
    Join Date
    Aug 2003
    Posts
    1,199
    Also if you dont mind windows specific code you can look up QueryPerformanceCounter and QueryPerformanceFrequency.

  4. #19
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Checked and found that time_T pretty much has to be an integer.
    No, it doesn't. time_t can be a floating point type just as easily as a signed or unsigned integral type. The size and representation are completely up to the implementation, so you cannot assume anything more than the fact that time_t is arithmetic, and can be used to compare with (time_t)-1. Everything else is non-portable.
    My best code is written with the delete key.

  5. #20
    Registered User
    Join Date
    Jul 2004
    Posts
    25
    unless you wanted it to be syncronized while the computers shut down or the same as the computer clock you can do this
    Code:
    #include <iostream.h>
    #include <windows.h>
    int main()
    {
    int loop; // in case you wanted it to do something over and over
    for (loop=0;loop>=0;loop++)
    {
    Sleep(60000); // a minute, one second is 1000, do the math
    cout << "\a";
    }
    
    return 0;
    }
    almost positive i didn't make any mistakes-i hope

  6. #21
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by killdragon
    unless you wanted it to be syncronized while the computers shut down or the same as the computer clock you can do this
    Code:
    #include <iostream.h>
    #include <windows.h>
    int main()
    {
    int loop; // in case you wanted it to do something over and over
    for (loop=0;loop>=0;loop++)
    {
    Sleep(60000); // a minute, one second is 1000, do the math
    cout << "\a";
    }
    
    return 0;
    }
    almost positive i didn't make any mistakes-i hope
    a few, actually... here's what the code should look like:
    Code:
    #include <iostream> //<iostream.h> is depreciated
    #include <windows.h> //not too sure about this one
    
    int main()
    {
      //for (int loop=0;loop>=0;loop++) //infinite loop - might as well declare loop here
              //because it most likely won't be used outside the 
              //scope of the loop
    
      for(;;)  //does the same as above, but saves a teeny bit of memory
      {
        Sleep(60000); //inadvisable - not portable, but it does free up the CPU
        cout << "\a";  //ringing the system bell every minute... 
      }
    
    return 0;
    }
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #22
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >//<iostream.h> is depreciated
    Deprecated means that something is still standard but not assured to be in the next revision. iostream.h is not a part of the C++ standard at all, deprecated or not. So while an implementation is allowed to give you iostream.h according to the rules of implementation-dependent extensions, the standard makes no guarantees as to its contents. I could legally write a compiler that supports iostream.h and leave it empty.

    >//not too sure about this one
    It should exist on a Windows box, otherwise I wouldn't hold my breath.
    My best code is written with the delete key.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 12:23 AM
  2. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  3. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  4. Making a Timer
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2002, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21