0

I was going through the make program's source code and I came across the following function declaration:

    struct dep *
    read_all_makefiles (makefiles)
    char **makefiles;
    { ... followed by function code ...

How do we decipher this declaration?

Aris totle
  • 61
  • 2
  • 5

1 Answers1

1

It's the old K&R style of function parameter declaration, prior to the ANSI/ISO standard C. This style is outdated now but can still be found in some very old codes. Although it's still in standard, it's recommended not to write like this anymore.

To decipher, simply move the parameter declaration list back to the function prototype, one-by-one, with the identifiers matching.

Quoting draft N1570, §6.9.1/13:

EXAMPLE 1

extern int max(int a, int b)
{
    return a > b ? a : b;
}

EXAMPLE 2

extern int max(a, b)
int a, b;
{
    return a > b ? a : b;
}

See Alternative (K&R) C syntax for function declaration versus prototypes

iBug
  • 35,554
  • 7
  • 89
  • 134
  • @EricPostpischil Thanks. Answer corrected. – iBug Feb 01 '18 at 03:44
  • It should also be mentioned this is not simply a different style of declaration. They operate differently. When a function with a prototype is called, the arguments are converted to the types of the parameters. When an identifier-list style function is called, the default argument promotions are performed. (A function declaration in the identifier-list style is not a prototype. The C standard defines a *function prototype* as a declaration of a function that declares the types of its parameters). There are additional technical differences. – Eric Postpischil Feb 01 '18 at 04:01