[comp.std.c] ANSI standard for difftime

scott@tdpvax.UUCP (07/01/89)

I have a copy of _The Waite Group's Essential Guide to ANSI C_ and it has
difftime() defined as the __elapsed__ time between to time_t values.  It 
declaration is.

double difftime(time_t time2, time_t time1);

and it returns time2 - time1.


My question is can this value be negative?  Since elapsed time is normally
a positive value.  What should difftime do if time1 is greater than time2.  I
tried this under a VMS compiler and it returned a negative value.  So
what is the _OFFICIAL_ ANSI standard say.  Since the arguments for and
against have already been made please don't make them here.  If you have
access to the PANS draft or KNOW the answer please reply.    Thanx.


                                Scott King
                                trsvax!tdpvax!scott
                                trsvax!tdpvax!scott@uxc.cso.uiuc.edu

So when do we get to see Rocky take on the Karate kid.  Or Jason take on Jaws?

dfp@cbnewsl.ATT.COM (david.f.prosser) (07/06/89)

In article <11000001@tdpvax> scott@tdpvax.UUCP writes:
>
>
>I have a copy of _The Waite Group's Essential Guide to ANSI C_ and it has
>difftime() defined as the __elapsed__ time between to time_t values. 
>
>My question is can this value be negative?

The pANS says ``The difftime function computes [and returns] the
difference [in seconds] between two calendar times: time1 - time0,''
where the declaration is given as

	double difftime(time_t time1, time_t time0);

So there is no implication of an ordering of the two times.

Dave Prosser	...not an official X3J11 answer...