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

#include directives in a file should only be preceded by other preprocessor directives or comments

    Details

    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Legacy Key:
      PPIncludeNotAtTop
    • Covered Languages:
      C, C++, Objective-C
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min
    • MISRA C 2004:
      19.1
    • MISRA C 2012:
      20.1
    • MISRA C++ 2008:
      16-0-1
    • PC-Lint:
      9019

      Description

      To aid code readability, all the #include directives in a particular code file should be grouped together near the top of the file. The only items which may precede an #include in a file are other preprocessor directives or comments.

      Noncompliant Code Example

      #include <h1.h> /* Compliant */
      int32_t i;
      #include <f2.h> /* Noncompliant */
      

      Compliant Solution

      #include <h1.h>
      #include <f2.h>
      
      int32_t i;
      

      See

      • MISRA C:2004, 19.1 - #include statements in a file should only be preceded by other preprocessor directives or comments.
      • MISRA C++:2008, 16-0-1 - #include directives in a file shall only be preceded by other preprocessor directives or comments.
      • MISRA C:2012, 20.1 - #include directives should only be preceded by preprocessor directives or comments

        Attachments

          Issue Links

          1.
          C-Family RSPEC-4361 Language-Specification Active Unassigned

            Activity

              People

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

                Dates

                • Created:
                  Updated: