[asterisk-dev] timeval.tv_sec is time_t. How to print/scan?

Alexander Traud pabstraud at compuserve.com
Mon Feb 26 04:26:55 CST 2018


> As that link shows ...

The link explains, that one should not assume any datatype for time_t. Therefore, I would use it like an abstract data-type. However, the Asterisk project might have assumptions about the platform. Then, difftime(.) could be used: <http://stackoverflow.com/a/34108260>. Or even a typecast to uintmax_t plus %ju might be used instead: <http://pubs.opengroup.org/onlinepubs/9699919799/functions/time.html>.

> ... head off nuisance compiler messages ...

With the wrong typecast, one could end up in Year 2038 problems. Therefore, instead of %lu, at least %llu is to be used.

> ... some compilers are stupid enough to still complain ...

On the latest OpenBSD with its base compiler clang, I get several compiler warnings related to this. I have to fix those now. So, it is more about the platform in my case. Therefore, I am asking. Looking at those code parts, I prefer %ju plus a typecast to uintmax_t right now.





More information about the asterisk-dev mailing list