1

For this quote:

An identifier list in a function declarator that is not part of a definition of that function shall be empty.

what is the difference between identifier list and parameter list and can someone provide an example for this quote.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
Sabrina
  • 1,460
  • 11
  • 23

2 Answers2

7

The "identifier list" is only used in obsolete "K&R style" functions. New code written today would never use it. You can see more details here: https://stackoverflow.com/a/3092074/4323

It's something like this:

void func(identifier-list)
declaration-list
{
    body
}

When they say it shall be empty, they mean that even admitting the possibility of ancient code, you are not allowed to have this in a declaration which does not define a function. So for example this is not allowed:

void func(x) int x;
Community
  • 1
  • 1
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • What about `shall be empty` ? – Sabrina Feb 21 '17 at 12:52
  • It is the opposite switch them . – Sabrina Feb 21 '17 at 12:53
  • @Sabrina that's pretty clear isn't it? "shall be empty" means there cannot be anything in between the parentheses, for a declaration that is not a definition. So you cannot write `void func(x);` – M.M Feb 21 '17 at 12:54
  • @M.M so the quote is only restricted to old style.( K&R ) – Sabrina Feb 21 '17 at 12:58
  • The standard is written this way because the grammar rules for function declarations treat `func()` as having an empty identifier-list between the parentheses. So identifier-lists have to be allowed in function declarations ... but only if they are empty. – zwol Feb 23 '17 at 18:58
2

Identifier list without identifiers' definitions says nothing about the types of function parameters. So it does not make sense to specify an identifier list for a function declaration when it is not at the same time a function definition.

So this restriction of the cited quote is used.

Here is an example

#include <stdio.h>

void f();

int main(void) 
{
    int x = 10;
    f( x );

    return 0;
}

void f( x ) 
int x;
{
    printf( "x = %d\n", x );
}

When a parameter list is used the compiler can check a call of a function that valid arguments are passed to the function. So it is better always to use parameter list instead of identifier list.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335