C6334
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at 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: