Why should ftime not be used?

时间:2017-06-09 12:44:57

标签: c linux time

Quoting man 3 ftime:

This function is obsolete. Don't use it. If the time in seconds suffices, time(2) can be used; gettimeofday(2) gives microseconds; clock_gettime(2) gives nanoseconds but is not as widely available.

Why should it not be used? What are the perils?

I understand that time(2), gettimeofday(2) and clock_gettime(2) can be used instead of ftime(3), but ftime(3) gives out exactly milliseconds, and this I find convenient, since milliseconds is the exact precision I need.

1 个答案:

答案 0 :(得分:1)

此类建议旨在帮助您使程序可移植并避免各种陷阱。虽然ftime功能可能无法从拥有它的系统中删除,但是您的软件移植到的新系统可能没有它,并且您可能会遇到问题,例如:如果时区的系统模型演变为不能以ftime结构的格式方便地表达的东西。