Warning C6387 Visual Studio

Viewed 1441

What is Visual Studio trying to tell me with this warning?

Warning

According to the docs, this warning is when you're passing a potentially null value to a parameter.

But I'm checking for null with if (hwnd) before calling these functions.

if (hwnd) {
    GetClientRect(hwnd, (LPRECT)&rMyRect);
    ClientToScreen(hwnd, (LPPOINT)&rMyRect.left);
    ClientToScreen(hwnd, (LPPOINT)&rMyRect.right);
}
3 Answers

The fact that you test for it is not relevant, the compiler isn't detecting that test. You can, however, use:

#pragma warning(suppress : 6387)

on the prior line and that will prevent the message (or use __Pragma(warning(suppress : 6387)) but I prefer the #pragma form.

Being the IntelliSense undeline what you are trying to get rid of (not the compile-time warning), it looks like there is no specific option to force IntelliSense to ignore that warning. You could disable it as a whole from the Visual Studio window, under Tools->Options->Text Editor->C/C++->Advanced, Look at the right for the section "Code Analysis"; under this section, set "Disable C++ Code Analysis Experience" to True.

Tools->Options->Text Editor->C/C++->*Advanced

If you test hwnd for 0 the warning doesn't appear;

if (hwnd != 0) {
    GetClientRect(hwnd, (LPRECT)&rMyRect);
    ClientToScreen(hwnd, (LPPOINT)&rMyRect.left);
    ClientToScreen(hwnd, (LPPOINT)&rMyRect.right);
}

There is a difference between NULL, no value, and 0, the value zero.

Related