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

----
int max_seconds = 30;
time_t start = time(NULL);

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


== Compliant Solution

----
int max_seconds = 30;
time_t start = time(NULL);
time_t now = start;

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


== See

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



ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
