I know that time_t is a long int on my system implementation. For the sake of experimenting, let's initialize it with INT_MAX. The data are displayed correctly, and running the code some second later decreases the counter accordingly.
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<limits.h>
int main(){
/* Set the current and a very large time */
time_t now;
time(&now);
time_t max = INT_MAX;
/* Print them on screen. */
printf("Last time: %s", ctime(&max));
printf("\nCurrent time: %s", ctime(&now));
/* Compute their difference */
double remaining = difftime(max, now);
printf("Remaining seconds (difftime): %lf\n", remaining);
return 0;
}
The problem is: when I replace INT_MAX with LONG_MAX, I obtain two apparently strange behaviors.
ctime(&max) returns a NULL. The reason might be that, if I remember correctly, the string is supposed to have maximum length 26, in this case exceeded. Am I right?
if I run the code some seconds later, the variable "remaining" is still the same, conversely to the MAX_INT case where it decreases second after second. How can I explain such a behavior? (these values are surely below DBL_MAX)
EDIT: sorry, I wrote "size_t" instead of "time_t" in my previous version, my mistake.