I'm trying to calculate difference between two time_t.
but difftime returns its first parameter instead of the difference!
My code is:
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main(){
time_t etime_t,now_t;
double time_diff;
now_t=1388525484L;
etime_t=1389338644L;
time_diff=difftime(now_t,etime_t);
printf("%f",time_diff);
}
And it prints:
1388525484.000000
I'm compiling with GCC (in MinWG)
What is the problem?
A MinGw bug. They compile difftime to a call of a standard windows function. However, they call a 32 bit version of difftime, even if arguments are 64 bits. This gives the expected result as it substracts higher half of the first argument (which is 0) from its lower half. See bug report here. It can be temporarily fixed by inserting
before including time.h