
Need some explanation using ctime.
Quote:
> Could somebody clearly explain me why this work file (twoprintf.c):
> #include <stdlib.h>
> #include <time.h>
> main() {
> time_t start;
> time_t final;
> start=975508641;
> final=976212675;
It doesn't; you're not guaranteed that time_t is a long or whatever. If
this happens to give you useful times, that's by accident.
Quote:
> printf("Start Time : %s*\n", ctime(&start));
> printf("Final Time : %s*\n", ctime(&final));
> exit(0);
> }
> #include <stdlib.h>
> #include <time.h>
> main() {
> time_t start;
> time_t final;
> start=975508641;
> final=976212675;
Ditto.
Quote:
> printf("Start Time : %s*\nFinal Time : %s*\n",
> ctime(&start),
> ctime(&final)
> );
> exit(0);
> }
> Giving this wrong output :
> **************
> running oneprintf
> Start Time : Wed Nov 29 15:37:21 2000
> *
> Final Time : Wed Nov 29 15:37:21 2000
> *
> **************
That output is, barring the superfluous text which wasn't printed by
your program, correct.
As for the times being equal: ctime() puts its result in a static
buffer, which you overwrite twice in the same parameter list. Since this
invokes undefined behaviour (writing the same object twice between
consecutive sequence points), the result could be anything the compiler
likes. Instead, you get the logical result; you got lucky.
Richard