return value for time()
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > return value for time()




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    return value for time()  
shyam


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-08-06 07:49 AM

Hi All

We all know that the time() function returns us the time in seconds
since epoch.

I have a doubt regarding the return value of ftime().
i HAVE A C APPLICATION WHICH IS HEAVILY DEPENDENT ON TIME() FUNCTION
SO I WANT TO MAKE SURE THAT IT RETURNS THE CORRECT VALUE
I.E I WANT TO DO ERROR CHECKING ON RETURN VALUS

i CHECKED THE MANUALS WHICH SAYS THAT IN CASE OF ERROR TIME()
RETURNS (time_t)-1.
How do i do that in my program

will something like this below work....

time_t epoch;

epoch = time(NULL);

if(epoch == (time_t)-1)
{
//handle error
}

is this ok  and enough?
please advice

regards
shyam






[ Post a follow-up to this message ]



    Re: return value for time()  
jakob


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-08-06 07:49 AM

On 2006-03-08, shyam <shyam.geek@gmail.com> wrote:
> time_t epoch;
>
>  epoch = time(NULL);
>
> if(epoch == (time_t)-1)
> {
> //handle error
> }
>
> is this ok  and enough?
> please advice

Should be.

jakob





[ Post a follow-up to this message ]



    Re: return value for time()  
Rainer Temme


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-08-06 12:52 PM

shyam wrote:

> time_t epoch;
>
>  epoch = time(NULL);
>
> if(epoch == (time_t)-1)
> {
> //handle error
> }
>
> is this ok  and enough?

Hi Shyam

Well, all other values are (at least in principle) legal
returnvalues. Only the special case (time_t)-1 is reserved to
indicate an error.

However, if you have some additional knowledge about the
time your program is used you could do some additional checking.
For example, if you know, that your program will not be used
before the year 2006, then any returnvalue, that computes
to a year between the_epoch and 2005 could be regarded as
invalid ... at least such a value would indicate that
the computer clock goes wrong.
Same thing ... if you dont expect this version of the program
to run (unmodified) after 2008 ... well, regard everything
bigger that 2008 as an error as well.

Rainer





[ Post a follow-up to this message ]



    Re: return value for time()  
Keith Thompson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-10-06 07:49 AM

Rainer Temme <Rainer.Temme@NoSpam.Siemens.Com> writes:
[...]
> However, if you have some additional knowledge about the
> time your program is used you could do some additional checking.
> For example, if you know, that your program will not be used
> before the year 2006, then any returnvalue, that computes
> to a year between the_epoch and 2005 could be regarded as
> invalid ... at least such a value would indicate that
> the computer clock goes wrong.
> Same thing ... if you dont expect this version of the program
> to run (unmodified) after 2008 ... well, regard everything
> bigger that 2008 as an error as well.

If you don't expect your program to run unmodified after 2008, it
almost certainly will run unmodified after 2008 (see Murphy's Law).

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.





[ Post a follow-up to this message ]



    Re: return value for time()  
Jordan Abel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-10-06 10:57 PM

On 2006-03-10, Keith Thompson <kst-u@mib.org> wrote:
> Rainer Temme <Rainer.Temme@NoSpam.Siemens.Com> writes:
> [...] 
>
> If you don't expect your program to run unmodified after 2008, it
> almost certainly will run unmodified after 2008 (see Murphy's Law).

And If you don't expect your program to run unmodified before 2006, it
almost certainly will run unmodified before 2006. (Murphy's law of
temporal mechanics)





[ Post a follow-up to this message ]



    Re: return value for time()  
Keith Thompson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-11-06 01:47 AM

Jordan Abel <random832@gmail.com> writes:
> On 2006-03-10, Keith Thompson <kst-u@mib.org> wrote:
[...] 
>
> And If you don't expect your program to run unmodified before 2006, it
> almost certainly will run unmodified before 2006. (Murphy's law of
> temporal mechanics)

That would have been a lot more convincing if you had posted before I
did.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.





[ Post a follow-up to this message ]



    Re: return value for time()  
Jordan Abel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-11-06 07:48 AM

On 2006-03-11, Keith Thompson <kst-u@mib.org> wrote:
> Jordan Abel <random832@gmail.com> writes: 
> [...] 
>
> That would have been a lot more convincing if you had posted before I
> did.

How do you know I didn't? Propagation delays and all that





[ Post a follow-up to this message ]



    Re: return value for time()  
Micah Cowan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-11-06 07:48 AM

Jordan Abel <random832@gmail.com> writes:

> On 2006-03-11, Keith Thompson <kst-u@mib.org> wrote: 
>
> How do you know I didn't? Propagation delays and all that

What, aside from the fact that you /quoted/ his message? ;-)





[ Post a follow-up to this message ]



    Re: return value for time()  
Jordan Abel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-11-06 12:48 PM

On 2006-03-11, Micah Cowan <micah@cowan.name> wrote:
> Jordan Abel <random832@gmail.com> writes:
> 
>
> What, aside from the fact that you /quoted/ his message? ;-)

Yeah, but we _were_ talking about temporal mechanics.





[ Post a follow-up to this message ]



    Re: return value for time()  
Rainer Temme


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-13-06 12:51 PM

Micah Cowan schrieb:
> Jordan Abel <random832@gmail.com> writes:
> 
>
> What, aside from the fact that you /quoted/ his message? ;-)

Well, this is the whole reason, why temporal mechanics
are _that_ hard to understand!

(I wrote what I wrote, because I knew, we would have a
funny little thread ;-) )

Rainer





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:57 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register