|
Home > Archive > Unix Programming > March 2006 > return value for time()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
return value for time()
|
|
|
| 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
| |
|
| 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
| |
| Rainer Temme 2006-03-08, 7:52 am |
| 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
| |
| Keith Thompson 2006-03-10, 2: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.
| |
| Jordan Abel 2006-03-10, 5: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)
| |
| Keith Thompson 2006-03-10, 8:47 pm |
| 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.
| |
| Jordan Abel 2006-03-11, 2: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
| |
| Micah Cowan 2006-03-11, 2: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? ;-)
| |
| Jordan Abel 2006-03-11, 7:48 am |
| 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.
| |
| Rainer Temme 2006-03-13, 7:51 am |
| 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
|
|
|
|
|