Watch your double calls to ctime() and friends
I fell into this trap (again) today:
Although the time_t variables t1 and t2 contain different values, the output of the printf() statement above is two similar date strings. Indeed, ctime() places the resulting date string in a static buffer, and returns a reference to this static buffer. Here, the same reference is placed twice on the stack.
printf("%s%s", ctime(&t1), ctime(&t2);
Although the time_t variables t1 and t2 contain different values, the output of the printf() statement above is two similar date strings. Indeed, ctime() places the resulting date string in a static buffer, and returns a reference to this static buffer. Here, the same reference is placed twice on the stack.
0 Comments:
Post a Comment
<< Home