yes. if you want more than that at the resolution that clock()
What do you mean?
If your code is relying on such information, then it is no longer
portable.
There is NO way to combine time() and clock(), as they return completely
different times. Imagine that your program is running together with 9
other programs, all 10 being CPU-bound. The time interval reported by
time() will be about 10 times as large as the time interval reported by
clock().
You don't need to combine them. Check clock() and time() periodically.
Compute the difference between the last call to clock() and this
one, and add it to a running sum in a variable with enough range
to handle the sum with reasonable precision and range (e.g. long
double, or use a bignum package). Compute the difference between
the last call to time() and this one. If it's longer than the
fastest possible wraparound time (e.g. 36 minutes above), you *MIGHT*
have blown it and your result should be considered possibly inaccurate.
If it's not, you should have reasonable accuracy.
Things are even hairier if the system load is variable during the
interval (which is quite common in practice, when sharing a system with
other people).
In the above situation it doesn't get hairier, but you might
actually get an accurate answer even if you're not sure it is accurate.
Now, about computing the wraparound time: you know that difftime()
returns the difference of two times in units of seconds, and you
know that the difference of two clock_t values is in units of
(1.0/CLOCKS_PER_SEC) seconds. Further, it is a reasonable guess
that if clock_t is signed (which you can test at runtime) and if
sizeof(clock_t) is equal to one (or more) of sizeof(short),
sizeof(int), sizeof(long), or sizeof(long long), the maximum value
of a clock_t is very likely equal to the corresponding SHRT_MAX,
INT_MAX, LONG_MAX, or LLONG_MAX. If it's unsigned you can determine
the maximum value by setting a clock_t variable to (clock_t)-1,
then assigning that to some variable with bigger range, such as
long double. Now, how much is that maximum value divided by
CLOCKS_PER_SEC in seconds? It's OK if you guess low.
Now, you might get in trouble if your program can be heavily
multi-threaded (no, I'm not talking about a thread-aware program,
I'm talking about the compiler dividing the program into threads
on its own) by a smart compiler (and is running on, for example,
a kilo-processor array) and clock_t time in seconds goes by faster
than time_t time.
Gordon L. Burditt