Details
-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:Move this array index inside the brackets.
-
Highlighting:
-
Default Severity:Blocker
-
Impact:High
-
Likelihood:High
-
Default Quality Profiles:Sonar way, MISRA C++ 2008 recommended
-
Covered Languages:C, C++, Objective-C
-
Remediation Function:Constant/Issue
-
Constant Cost:5min
-
Analysis Scope:Main Sources, Test Sources
Description
While C syntax considers array subscripts ([]) as symmetrical, meaning that a[i] and i[a] are equivalent, the convention is to put the index in the brackets rather than the array name. Inverting the index and array name serves no purpose, and is very confusing.
Noncompliant Code Example
10[P1] = 0; // Noncompliant dostuff(i[arr]); // Noncompliant
Compliant Solution
P1[10] = 0; dostuff(arr[i]);
Attachments
Issue Links
- is related to
-
CPP-1629 Rule: Array indices should be placed between brackets
-
- Closed
-