What Is the High Integrity C++ (HIC++) Coding Standard?
High Integrity C++ (HIC++) is a coding standard developed by Perforce (formerly PRQA).
HIC++ helps developers write high quality, maintainable, portable, and robust code in modern C++ (C++11). Development teams in many industries use HIC++.
The latest version — version 4.0 — was published on October 3, 2013.
Back to topWhat Does the High Integrity C++ Coding Standard Cover?
The High Integrity C++ coding standard includes best practices for developing high-quality software. It specifies coding rules and gives examples of compliant and non-compliant code.
HIC++ Coding Rules
There are 155 coding rules in HIC++. The following are some of the most popular coding rules.
8.2.4
Do not pass std::unique_ptr by const reference
Rule 8.2.4 follows the advice of Herb Sutter. Passing by non-const reference signifies that the parameter is an in/out parameter. Passing by value signifies that the parameter is a sink (i.e. takes ownership and does not return it).
4.1.1
Ensure that a function argument does not undergo an array-to-pointer conversion
Rule 4.1.1 originates from the JSF AV C++ coding standard.
The issue arises because a function parameter that looks like an array is actually just a pointer:
void f1(int a[10]) { // Equivalent to void f1(int*)
a[8] = 0; // Out of Bounds when called from f2
}
void f2() {
int b[5];
f1(b); // Not illegal code!
}
You may assume that the array dimension in f1 is checked by the compiler. But no checking will take place. In JSF C++, the passing of array arguments isn’t allowed.
HIC++, however, allows arrays to be passed as arguments. But this is only when the dimension information is not lost:
void f1(int (&a)[10]) { // Parameter is reference to
// array of 10 elements.
a[8] = 0; // Guaranteed to be legal
}
void f2() {
int b[5];
f1(b); // Illegal - Compile Error
// Cannot convert int[5] to int[10]
}
2.1.1
Do not use tab characters in source files
Indenting code with spaces ensures that formatting is preserved when printing and across different editors or tools.
12.5.6
Use an atomic, non-throwing swap operation to implement the copy and move assignment operators
Rule 12.5.6 ensures the correct copying and moving of a class. And it provides strong exception safety.
This provides a simple and consistent way to layout members in a class, for example:
class A {
public:
A (A const &) …
A (A &&) …
A & operator=(A rhs) & noexcept {
swap (*this, rhs);
return *this;
}
};
2.2.1
Do not use digraphs or trigraphs
Rule 2.2.2 prevents the use of digraphs and trigraphs. Trigraphs, in particular, do not behave well with raw string literals in C++11.
[RELATED WHITE PAPER: HIGH INTEGRITY C++ CODING RULES]
Back to topHow to Use HIC++
The best way to comply with the HIC++ coding standard is to use a static code analyzer.
Helix QAC offers the greatest accuracy in complying with HIC++ rules.
Helix QAC also provides:
- Fully documented rule enforcement and message interpretation
- Supplied with extensive example code
- Fully configurable rules processing
- Compliance reports for functional safety audits