27 lines
491 B
Plaintext
27 lines
491 B
Plaintext
{cpp} 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 {cpp}:2008, 16-2-1
|
|
|