Address-of and dereference operators cancel each other out
ID |
c.maintainability.redundant_pointer_operators |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Redundant Operation |
Language |
C / C++ |
Description
This expression applies * and & back to back on the same operand, so one operator cancels the other and the pair has no effect beyond obscuring the intent. Remove the redundant pair and use the plain operand.
Rationale
This expression applies * and & back to back on the same operand, so one operator cancels the other and the pair has no effect beyond obscuring the intent. Remove the redundant pair and use the plain operand.
The following code illustrates the pattern detected by this rule:
void deref_of_address(int x)
{
// FLAGGED: Address-of and dereference operators cancel each other out
int y = *&x;
(void)y;
}