Passing system time to a function

This is a discussion on Passing system time to a function within the C++ Programming forums, part of the General Programming Boards category; How should I read a system time in a variable, if I want to pass that time later on to ...

  1. #1
    Unregistered
    Guest

    Passing system time to a function

    How should I read a system time in a variable, if I want to pass that time later on to a function? None of the ways I've tried has worked, so I really could use some advice. I'm using Visual C++ 6.0.

    Thanks in advance.

    Henry

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    Code:
    void foo ( time_t when );
    time_t now = time(NULL);
    foo ( now );
    What did you try?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Unregistered
    Guest
    Well, everything else but that. Appearantly I tried to do it harder than it had to.

    Thanks.

    Henry

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    There are other ways to do this with VC++, and a number of useful API functions for manipulating, displaying and calculating with dates and times. Look in the compiler help.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    7
    Originally posted by Salem
    Code:
    void foo ( time_t when );
    time_t now = time(NULL);
    foo ( now );
    What did you try?
    I am sorry to say, using time_t is poor programming. time_t is 32-bit long, therefore, it only supports up to year 2038, and it does not support daylight saving time. You will kick yourself in the head when a senior guy looked at that code which basically needs to be rewritten if all you use is time_t

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    > time_t is 32-bit long
    And when it's redeclared as something bigger, you only have to recompile the code, and the problem goes away for a few more million years

    Do you know nothing of writing portable programs?

  7. #7
    Unregistered
    Guest
    Originally posted by Salem
    > time_t is 32-bit long
    And when it's redeclared as something bigger, you only have to recompile the code, and the problem goes away for a few more million years

    Do you know nothing of writing portable programs?

    well, right now it is not 64-bit yet, and you are programming now, what happens in your program that someone choose a date beyond year 2038 or the data/input by mistake is beyond year 2038, then you get unprecitable results. It is like using uninitalized variable in release build if you know what that will amount to. Your boss don't let you wait till they switch to 64-bit in who knows when.

  8. #8
    Registered User
    Join Date
    Feb 2002
    Posts
    7
    the previous was my post. And what happens if user adjust window time to year 2050. then your program will act really funny...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  3. Read and set\change system time
    By Hexxx in forum C++ Programming
    Replies: 9
    Last Post: 01-02-2006, 06:11 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  5. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM

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