Declaring multiple variable on one line is difficult to read.
Noncompliant Code Example
class MyClass {
private int a, b;
public void method(){
int c; int d;
}
}
Compliant Solution
class MyClass {
private int a;
private int b;
public void method(){
int c;
int d;
}
}
See
- MISRA C++:2008, 8-0-1 - An init-declarator-list or a member-declarator-list shall consist of a single init-declarator or member-declarator
respectively
- CERT, DCL52-J. - Do not declare more than one variable per declaration
- CERT, DCL04-C. - Do not declare more than one variable per declaration
- CERT, DCL04-CPP. - Do not declare more than one variable per declaration