== Why is this an issue?

While you can perform arithmetic on a ``++time_t++`` type, you may not get the results you expect from the operation because the way that a time is encoded within the type is unspecified. Therefore there is no safe way to manually perform arithmetic on ``++time_t++`` variables despite the fact that the ISO C standard defines ``++time_t++`` as an "arithmetic type". The relevant function calls should be used instead.


=== Noncompliant code example

[source,cpp]
----
int max_seconds = 30;
time_t start = time(NULL);

while (time(NULL) < start + max_seconds) {  // Noncompliant
  //...
}
----


=== Compliant solution

[source,cpp]
----
int max_seconds = 30;
time_t start = time(NULL);
time_t now = start;

while (difftime(now, start) < max_seconds) {
  now = time(NULL);
  //...
}
----


== Resources

* https://wiki.sei.cmu.edu/confluence/x/09UxBQ[CERT, MSC05-C.] - Do not manipulate ``++time_t++`` typed values directly



ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Use the correct function to perform this calculation.


'''
== Comments And Links
(visible only on this page)

=== on 19 Sep 2014, 13:39:33 Freddy Mallet wrote:
@Ann, I would improve the "Noncompliant Code Example" because when we don't know that's the type of time_limit variable is int, the example is meaningless.

endif::env-github,rspecator-view[]
