variables between function header and body

G

gkelly

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;
}
 
I

Ian Collins

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???

This is old K&R style code, from the days before C89.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top