Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
C6334
Collapse the table of content
Expand the table of content

C6334

warning C6334: sizeof operator applied to an expression with an operator may yield unexpected results

This warning indicates a misuse of the sizeof operator. The sizeof operator, when applied to an expression, yields the size of the type of the resulting expression.

For example, in the following code:

     char     a[10];
     size_t   x;

     x = sizeof (a - 1);

x will be assigned the value 4, not 9, because the resulting expression is no longer a pointer to the array a, but simply a pointer.

The following code generates this warning:

void f( )
{   
  size_t x;
  char a[10];

  x= sizeof (a - 4);
  // code...
}

To correct this warning, use the following code:

void f( )   
{
  size_t x;
  char a[10];

  x= sizeof (a) - 4;
  // code...
} 
Show:
© 2015 Microsoft