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

Macros should not be redefined

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Remove this redefinition or precede it with "#undef" first.
    • Highlighting:
      Hide

      primary macro name
      secondary previous definition

      Show
      primary macro name secondary previous definition
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way, MISRA C++ 2008 recommended
    • Covered Languages:
      C, C++, Objective-C
    • Irrelevant for Languages:
      ABAP, C#, Cobol, CSS, Flex, HTML, Java, JavaScript, PHP, PL/I, PL/SQL, Python, RPG, Swift, VB.Net, VB6, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources, Test Sources

      Description

      A macro definition should not be redefined without marking that intent specifically by un-defining it first.

      Noncompliant Code Example

      #define A 1
      #define A 2
      

      Compliant Solution

      #define A 1
      #undef A
      #define A 2
      

      Exceptions

      If the redefinition has the same value as the original one. This is consistent with most C compilers warnings.

      #define A 1
      #define A 1
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              jeanchristophe.collet Jean-Christophe Collet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: