2.1 Character sets

2.1.1 Do not use tab characters in source files

Tab width is not consistent across all editors or tools. Code indentation can be especially confusing when tabs and spaces are used interchangeably. This may easily happen where code is maintained using different editors. In string and character literals \t should be used in preference to a direct tab character.

#include <cstdint>
               
void do_something();
void do_something_else();
               
void foo (int32_t i)
{
if (i)
do_something ();
do_something_else (); // @@- Non-Compliant: tab character used to indent this statement -@@
}
               
void bar (int32_t i)
{
if (i)
do_something ();
do_something_else (); // this is what the code looks like with
                      // tab width of 8 instead of 4 as above
}

Indenting code only with spaces ensures that formatting is preserved when printing and across different editors or tools.

References

  • HIC++ v3.3 – 14.2

Click here for references