Share via


C6269

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.

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 will not behave as intended because *p++ construct is interpreted as * (p++). instead of (*p)++.

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 ...
}