rspec/rules/S971/rule.adoc

27 lines
487 B
Plaintext
Raw Normal View History

C++ provides safer ways of achieving what is often done using the pre-processor, by way of inline functions and constant declarations.
== Noncompliant Code Example
----
#ifndef HDR // Compliant
#define HDR // Compliant
#define X(Y) (Y) // Noncompliant
#define PI 3.141592 // Noncompliant
#endif
----
== Compliant Solution
----
template<typename T> inline T function(T t) { return t; } // Compliant
double const PI = 3.141592; // Compliant
----
== See
* MISRA C++:2008, 16-2-1