Edit

Share via


Warning C6269

Possible incorrect order of operations: dereference ignored

This warning indicates that the result of a pointer dereference is being ignored, which raises the question of why the pointer is being dereferenced in the first place.

Remarks

The compiler will correctly optimize away the gratuitous dereference. In some cases, however, this defect may reflect a precedence or logic error.

One common cause for this defect is an expression statement of the form:

*p++;

If the intent of this statement is simply to increment the pointer p, then dereference is unnecessary; however, if the intent is to increment the location that p is pointing to, then the program won't behave as intended because p++ construct is interpreted as (p++) instead of (*p)++.

Code analysis name: POINTER_DEREF_DISCARDED

Example

The following code generates this warning:

#include <windows.h>

void f( int *p )
{
  // code ...
  if( p != NULL )
    *p++;
  // code ...
}

To correct this warning, use parentheses as shown in the following code:

#include <windows.h>

void f( int *p )
{
  // code ...
  if( p != NULL )
    (*p)++;
  // code ...
}