c - 为什么 difftime() 会返回一个 double 值?

标签 c posix

来自 difftime()'s man page :

double difftime(time_t time1, time_t time0);

The difftime() function returns the number of seconds elapsed between time time1 and time time0, represented as a double.

既然“秒数”不需要 float ,为什么这个函数返回一个double

最佳答案

documentation在这一点上更清楚:

On POSIX systems, time_t is measured in seconds, and difftime is equivalent to arithmetic subtraction, but C and C++ allow fractional units for time_t.

虽然POSIX requires time_t to be an integer type ,对于非 POSIX 系统,这可能会返回小数秒。

关于c - 为什么 difftime() 会返回一个 double 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34457931/

相关文章:

c - C 中的 IIR 滤波器实现

C 风格类型注解与其他注解

c - inet_ntop 的第二个参数的正确类型/格式是什么?

c++ - fallocate 与 posix_fallocate

c - C中读写锁的线程安全销毁

c - 使用 OpenSSL 进行 DSA 签名

c - 信号量无法正常工作

c++ - Visual Studio 中的 pthread_create 错误

c - POSIX 系统上 regex.h header 的不同实现背后的算法类型

c - Win32 API 中 Posix popen() 的等价物是什么?