[RLUG] C question
sstrahm4 at charter.net
sstrahm4 at charter.net
Mon Feb 12 08:47:25 PST 2007
Folks-
Because Austin's response and my response contradict, I thought I would tell that Austin's is correct.
The C 2nd Ed (1988) specifies the "new" way of doing declaration lists, and looking at the C History at http://cm.bell-labs.com/cm/cs/who/dmr/chist.html, it shows the old way of making function calls.
I first coded in C in 1984, but did not do any serious coding in C until 1992, after the 2nd Ed came out.
I hate spreading ignorance....
By the way, the 2nd Ed grammar tells that this format remains acceptable. It would be interesting to know if it is acceptable today.
-Scott
---- Austin Stanhope <stanhope at cse.unr.edu> wrote:
> It's an older C way of giving types to the function arguments. It has
> since been changed so you can do it the old way, or the way most of us
> are used to doing it (the term most is open to interpretation here). It
> is equivalent to saying:
>
> int timeval_subtract (timeval *result, timeval *x, timeval *y)
> {
> // do stuff
> }
>
> -Austin
>
>
>
> Grant Kelly wrote:
> > 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;
> > }
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > RLUG mailing list
> > RLUG at rlug.org
> > http://lists.rlug.org/mailman/listinfo/rlug
> >
>
>
> --
> Austin Stanhope www.cse.unr.edu/~stanhope
> Robotics Research www.cse.unr.edu/~society
> Computer Science and Engineering www.cse.unr.edu
> University of Nevada, Reno www.unr.edu
>
> Abuse it and you'll loose it. I WILL Procmail you.
> Think before you click that forward button.
>
>
>
> _______________________________________________
> RLUG mailing list
> RLUG at rlug.org
> http://lists.rlug.org/mailman/listinfo/rlug
More information about the RLUG
mailing list