Attempting to make a comparison between pointers using >, >=, < or <= will produce undefined behavior if the two pointers point to
different arrays.
Additionally, directly comparing two arrays for equality or inequality has been deprecated in C++.
However, equality or inequality between an array and a pointer is still valid
Noncompliant code example
void f1 ( )
{
int a1[ 10 ];
int a2[ 10 ];
int * p1 = a1;
if ( p1 < a2 ) // Non-compliant, p1 and a2 point to different arrays.
{
}
if ( p1 - a2 > 0 ) // Non-compliant, p1 and a2 point to different arrays.
{
}
if ( a1 == a2) // Non-compliant (in C++). Comparing different array for equality is deprecated
{
}
}
Compliant solution
void f1 ( )
{
int a1[ 10 ];
int * p1 = a1;
if ( p1 < a1 ) // Compliant, p1 and a1 point to the same array.
{
}
if ( p1 - a1 > 0 ) // Compliant, p1 and a1 point to the same array.
{
}
if ( p1 == a2 ) // Compliant, comparing a pointer and an array for equality is valid
{
}
}