>
>
>
V808. An array/object was declared but …


V808. An array/object was declared but was not utilized.

The analyzer has detected a code that can be simplified. A function code contains local variables which are not used anywhere.

The analyzer generates this warning in the following cases:

  • An object array is created but not used. It means that the function uses more stack memory than necessary. First, it may lead to a stack overflow. Second, it may reduce the efficiency of the microprocessor cache.
  • Class objects are created but not used. The analyzer doesn't warn about all such objects, but only about those which certainly don't need to be created without using them. For instance, these are std::string or CString. Creation and destruction of such objects is just a waste of processor time and stack memory.

The analyzer doesn't generate the warning if variables of built-in types are created: the compiler handles this very well. It also helps to avoid a lot of false positives.

Consider this sample:

void Foo()
{
  int A[100];
  string B[100];
  DoSomething(A);
}

The array of items of the 'string' type is declared but not used, while it still requires memory to be allocated for it and calling constructors and destructors. To optimize this code, we just need to delete the declaration of the unused local variable or array. This is the fixed code:

void Foo()
{
  int A[100];
  DoSomething(A);
}