简体   繁体   中英

Difference between identifier list and parameter list in function?

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.

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;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM