Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V561. Consider assigning value to...
menu mobile close menu
Additional information
toggle menu Contents

V561. Consider assigning value to 'foo' variable instead of declaring it anew.

Feb 04 2011

The analyzer detected a potential error: there is a variable in code which is defined and initialized but not being used further. Besides, there is a variable in the exterior scope which also has the same name and type. It is highly probable that the programmer intended to use an already existing variable instead of defining a new one.

Let's examine this sample:

BOOL ret = TRUE;
if (m_hbitmap)
  BOOL ret = picture.SaveToFile(fptr);

The programmer defined a new variable 'ret' by accident, which causes the previous variable to always have the TRUE value regardless if the picture is saved into a file successfully or not. This is the correct code:

BOOL ret = TRUE;
if (m_hbitmap)
  ret = picture.SaveToFile(fptr);

This diagnostic is classified as:

You can look at examples of errors detected by the V561 diagnostic.