3

While reading the source code for MINIX, I came across the following:

int do_read_write(rw_flag)
int rw_flag;                    /* READING or WRITING */
{

It looks like the middle line is used to declare the type of the rw_flag input to the function, but I have never seen this notation before. Is it any different from the following?

int do_read_write(int rw_flag) {

If not, does it serve any purpose, other than expanding the code so that it can be commented more?

Jon Claus
  • 2,862
  • 4
  • 22
  • 33

2 Answers2

5

This is a very old C style of declaration, from the first years (1980ies?). Yes, it means the same thing.

You should not use it anymore, it is not supported by most compilers anymore, and abandoned for a reason.

Aganju
  • 6,295
  • 1
  • 12
  • 23
1

This is a valid way to declare the parameters called declaration list (ISO/IEC 9899:TC3, 6.9.1, 1) …

6.9.1 Function definitions

Syntax

function-definition:

    declaration-specifiers declarator declaration-listopt compound-statement

 declaration-list:

   declaration

   declaration-list declaration

… but it will become invalid (ISO/IEC 9899:TC3, 6.11.7)

6.11 Future language directions

[…]

6.11.7 Function definitions

The use of function definitions with separate parameter identifier and declaration lists (not prototype-format parameter type and identifier declarators) is an obsolescent feature.

Community
  • 1
  • 1
Amin Negm-Awad
  • 16,582
  • 3
  • 35
  • 50