Why is this an issue?
Declaring multiple variables or members on the same line hinders readability. Moreover, as soon as they contain references, pointers, or
assignments, they become confusing for maintainers.
This rule raises an issue when a declaration declares multiple variables or members.
int i1, j1; // Noncompliant
int i2, *j2; // Noncompliant
int *i3,
&j3 = i2; // Noncompliant
Giving each declaration its own line makes the code more maintainable.
int i1;
int j1;
int i2;
int *j2;
int *i3;
int &j3 = i2;
Resources
Standards
- CERT, DCL04-C. - Do not declare more than one variable per declaration
External coding guidelines
- 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
- C++ Core
Guidelines - ES.10 - Declare one name (only) per declaration