Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-929

Functions without parameters should be declared with parameter type "void"

    Details

    • Message:
      Set this function's parameter list to "void"
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Covered Languages:
      C, Objective-C
    • Irrelevant for Languages:
      C++
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      1min
    • CERT:
      DCL20-C.
    • MISRA C 2004:
      16.5

      Description

      There is a real, functional difference between a function with an empty parameter list and one with an explicitly void parameter list: It is possible to pass parameters to a function with an empty list; the compiler won't complain. That is not the case for a function with a void list. Thus, it is possible, and even easy to invoke empty-list functions incorrectly without knowing it, and thereby introduce the kind of subtle bug that can be very difficult to track down.

      Noncompliant Code Example

      void myfunc ();  // Noncompliant
      
      //...
      
      void otherFunc() {
        int a = 4;
        //...
        myfunc(a); // Compiler allows this
      }
      

      Compliant Solution

      void myfunc ( void );
      
      //...
      
      void otherFunc() {
        int a = 4;
        //...
        myfunc(a); // Compiler error!
      }
      

      See

      • MISRA C:2004, 16.5 - Functions with no parameters shall be declared with parameter type void
      • CERT, DCL20-C. - Explicitly specify void when a function accepts no arguments

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                Anonymous
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: