【发布时间】:2017-08-04 20:11:31
【问题描述】:
两者都在我的简单测试代码中正常工作,但我想知道是否有任何真正的区别,或者在编码风格方面是否有任何一致同意的偏好。
附上示例代码:
#include <stdio.h>
#include <time.h>
int main(int argc, char **argv)
{
time_t now1, now2;
time(&now1);
now2 = time(NULL);
printf("now1 = %ld\n", now1);
printf("now2 = %ld\n", now2);
return 0;
}
编辑
我刚刚看到Keith Thompson's answer - 这个问题可能应该被标记为重复。
【问题讨论】:
-
注意:
time_t未定义为long,因此使用"%ld"打印不可移植。printf("now1 = %ld\n", (long) now1);稍微好一些。考虑printf("now1 = %s\n", ctime(&now1));或其他人。