2

Possible Duplicate:
Declaring function parameters after function name
C function syntax, parameter types declared after parameter list

I'm fairly new to C and was mucking around with timing and came across the following function. I can get it to work by passing pointers to it. I don't really understand whats happening here though. What does the third line do and how is the second line even legal?

int 
timeval_subtract (result, x, y)
     struct timeval *result, *x, *y;
{
  ... (function code here)
}
0

3 Answers 3

5

This is very old C syntax for function declaration. It is not recommended to use it.

http://msdn.microsoft.com/en-us/library/efx873ys.aspx

Sign up to request clarification or add additional context in comments.

Comments

3

Seems like some old C code. (Kernighan & Ritchie, according to the other answers.)

This defines the order of the arguments:

timeval_subtract (result, x, y)

This defines their types:

 struct timeval *result, *x, *y;

It's the same as:

int timeval_subtract (struct timeval *result,
                      struct timeval *x,
                      struct timeval *y)
{
    // ...
}

(Those structs are redundant in C++, and the newest version of C, IIRC.)

Comments

0

That looks like pretty ancient C, like K&R C or something... I do not think that's legal ANSI C.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.