In this section:
This error is generated whenever an expression tries to compare pointers that do not point into the same memory block. This only applies to the operators
<=. The operators
!= are exempt from this case.
The ANSI C-language specification declares this construct undefined except in the special case where a pointer points to an address one past the end of a block. Expression compares unrelated pointers
Code Description Enabled Reported Platform EXPR_UNRELATED_ PTRCMP Runtime Windows/Unix
Expression compares unrelated pointers
The following code illustrates the problem by comparing pointers to two data objects.
The error in this code is not that the two objects
b are of different data types (array vs. dynamic memory block), but that the comparison in line 12 attempts to compare pointers which do not point into the same memory block. According to the ANSI specification, this is an undefined operation.
Diagnosis at Runtime
- Line 1: Source line at which the problem was detected.
- Line 3: Description of the problem and the expression that is in error.
- Line 5: Description of the two pointers involved in the comparison. For each pointer, the associated block of memory is shown together with its size and the line number at which it was declared or allocated.
- Line 12: Stack trace showing the function call sequence leading to the error.
While this construct is technically undefined according to the ANSI C specification, it is supported on many machines and its use is fairly common practice. If your application genuinely needs to use this construct, you can suppress this message by suppressing
EXPR_UNRELATED_PTRCMP in the Suppressions Control Panel.