Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 1.43 KB

c6269.md

File metadata and controls

57 lines (42 loc) · 1.43 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Warning C6269
Warning C6269
11/04/2016
C6269
POINTER_DEREF_DISCARDED
__WARNING_POINTER_DEREF_DISCARDED
C6269
a01fa7fa-fc6c-4af7-ac8c-585e44e60cca

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