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
&j3 = i2; // Noncompliant
Giving each declaration its own line makes the code more maintainable.
int &j3 = i2;
- 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
- C++ Core
Guidelines - ES.10 - Declare one name (only) per declaration