Home > Enterprise >  Effects of the removal of K&R function definitions in C2x
Effects of the removal of K&R function definitions in C2x

Time:10-01

One of the changes for the upcoming C2x standard seems to be the

Removal of K&R function definitions

From what i understand the K&R style definitions is the reason why we have to declare a function that takes no parameters as

void foo(void);

instead of

void foo();

Does the removal of the K&R style in C2x mean we can/should now simply use empty brackets for functions that are taking no paramers like in other languages?

CodePudding user response:

K&R style function definitions are things like

int foo(a, b)
int a;
int b;
{
    /* function body here*/

They are completely orthogonal to the question of (void) vs () in a function declaration

CodePudding user response:

Here is Section 6.7.6.3 (Function declarators) item 13 of the Working Draft as of Dec, 2020:

For a function declarator without a parameter type list: if it is part of a definition of that function the function has no parameters and the effect is as if it were declared with a parameter type list consisting of the keyword void; otherwise it specifies that no information about the number or types of the parameters is supplied.157) A function declarator provides a prototype for the function if it includes a parameter type list.158) Otherwise, a function declaration is said to have no prototype.

So in a function definition, you will be able to omit (void), but you still have to include it in a function declaration.

  •  Tags:  
  • c
  • Related