# V2601. MISRA. Functions should be declared in prototype form with named parameters.

This diagnostic rule is based on the software development guidelines developed by MISRA (Motor Industry Software Reliability Association).

This diagnostic rule is relevant only to C. It's not safe to use the "K&R" function declaration as well as unnamed function parameters.

Old-style "K&R" function declarations do not carry information about the types and number of parameters, so the use of such functions can lead to errors.

The use of named function parameters provides valuable information about the function interface and allows you to track an error if the names in the declaration and definition do not match.

Code example:

    // header
    void draw();

    // .c file
    void draw(x, y)
      double x;
      double y;
    {
      // ....
    }

    // usage
    void foo()
    {
      draw(1, 2);
    }

The 'draw' function declaration doesn't have parameters. So, when you call the 'draw' function, 2 parameters of the 'int' type and not 'double' type are passed to it. It's an error. Function declaration with a prototype fixes the problem:

    // header
    void draw(double x, double y);

    // .c file
    void draw(double x, double y)
    {
      // ....
    }

If a function has no parameters, then the use of empty parentheses in its declaration is not correct, because such a declaration corresponds to the "K&R" style:

    void foo();

Such a declaration allows to pass any number of arguments. To explicitly indicate that a function has no parameters, you need to use the 'void' keyword:

    void foo(void);

Unnamed parameters make the function interface less understandable:

    void draw(double, double);

To avoid errors when you use a function, give names to parameters:

    void draw(double x, double y);

This diagnostic is classified as:

MISRA-C-2012-8.2 MISRA-C-2023-8.2