0

I was reading through GNU C library - Date-time - Data & Functions and came across this function definition:

int timeval_subtract (result, x, y)
 struct timeval *result, *x, *y;
{
    //do stuff
    return result;
}

I have never come across this argument passing before. -There is not type for the variables within the parenthesis (). -OK the type "struct timeval" comes later, but using the same variable names?

Is the above entirely equivalent to

int struct_timeval(struct timeval *result, struct timeval *x, struct timeval *y){

    //do stuff
}

or not?

nass
  • 1,453
  • 1
  • 23
  • 38
  • 1
    It is old style known as K&R style.There are lots of duplicate of this type of question on SO.Please refer Google. – Dayal rai Jul 11 '13 at 12:53

1 Answers1

1

It it is the old style of function declaration. It uses an identifier list in the declaration.

This kind of declaration is not equivalent to function prototypes. With a prototype, function arguments are converted to the type of parameters as if by assignment but without prototype default argument promotion occurs.

ouah
  • 142,963
  • 15
  • 272
  • 331
  • I am not sure I understand. "argument promotion"? – nass Jul 11 '13 at 13:48
  • @nass in the general case, it means arguments of type narrower than `int` (like `char`, `short`, ...) are converted to `int` and `float` is converted to `double`. – ouah Jul 11 '13 at 14:12