title: Calling a function every 40 second inside a while loop
body: <p>This code invokes a function for every 40 seconds inside a loop. Since time_t is signed in my linux system, I am doubtful about this condition:</p>
  
  <blockquote>
  <pre><code>if ((time_left &lt;= 0 || time_left &gt; interval))
  </code></pre>
  </blockquote>
  
  <p>Is only checking <code>(time_left &lt;= 0)</code> fine? I referred to some websites and they have also added a check for <code>time_left &gt; interval</code>. Is this check required?</p>
  
  <pre><code>int print_timed_op()
  {
      time_t        time_now;
      time_t        time_left;
      time_t        time_next_interval;
      int           interval = 40, hit_count =10; //40 second interval, 10 times
      time_next_interval = time(0) + interval;
  
     //tight loop
     while (1) {
           sleep(1);
           time_now = time(0);
           time_left = time_next_interval - time_now;
           /* here time_left &gt; interval check required ? */
           if ((time_left &lt;= 0 || time_left &gt; interval)) { 
                call_my_fuc();
                time_next_interval = time(0) + interval;
                time_left = interval;
                hit_count--;
           }
  
           if(hit_count &lt;= 0)
              break;
    }
    return 0;
  }
  </code></pre>
  
  <p>Note: I don't want to use a Linux timer system call or any other method to invoke the function periodically.</p>