[RLUG] C question

Grant Kelly gkelly at gmail.com
Sat Feb 10 18:18:48 PST 2007


I came across this code which does something I've never seen before. Could
someone explain what the variable declaration between the function header
and the function body do? Or at least point me in a direction to find out
for myself. Again, I know what the code does, but I don't know what the line
marked with <==== does.

Thanks,
Grant

int timeval_subtract (result, x, y)
     struct timeval *result, *x, *y;    <==== What does this do???
{
  /* Perform the carry for the later subtraction by updating y. */
  if (x->tv_usec < y->tv_usec) {
    int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
    y->tv_usec -= 1000000 * nsec;
    y->tv_sec += nsec;
  }
  if (x->tv_usec - y->tv_usec > 1000000) {
    int nsec = (y->tv_usec - x->tv_usec) / 1000000;
    y->tv_usec += 1000000 * nsec;
    y->tv_sec -= nsec;
  }

  /* Compute the time remaining to wait.
     tv_usec is certainly positive. */
  result->tv_sec = x->tv_sec - y->tv_sec;
  result->tv_usec = x->tv_usec - y->tv_usec;

  /* Return 1 if result is negative. */
  return x->tv_sec < y->tv_sec;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rlug.org/pipermail/rlug/attachments/20070210/ddeab034/attachment-0001.htm


More information about the RLUG mailing list