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)
}
Community
  • 1
  • 1
Steven
  • 120
  • 3

3 Answers3

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

Mysticial
  • 464,885
  • 45
  • 335
  • 332
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.)

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
0

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

K-ballo
  • 80,396
  • 20
  • 159
  • 169