Reputation: 4523
In Visual Studio 2012, when I try to compile the following c++ function:
void CCustToolBar::OnCustHelp(NMHDR* pNMHDR, LRESULT* /*pResult*/)
{
TRACE(_T("{ Help ID = %d }\n"), pNMHDR->idFrom);
}
I get the warning "warning C4100: 'pNMHDR' : unreferenced formal parameter"
Which doesn't make sense, as pNMHDR is being used. And if I try to comment it out:
void CCustToolBar::OnCustHelp(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
{
TRACE(_T("{ Help ID = %d }\n"), pNMHDR->idFrom);
}
I get the error "error C2065: 'pNMHDR' : undeclared identifier"
Which does make sense.
What am I missing here? Why am I getting warning C4100 when the variable is being used?
Upvotes: 1
Views: 375
Reputation: 10628
The MSDN page for TRACE says:
In the debug version of MFC, this macro sends the specified string to the debugger of the current application. In a release build, this macro compiles to nothing (no code is generated at all).
Therefore, you must be compiling in Release mode to get the warning, since the whole TRACE
call will not exist in that configuration.
If you change your code to this:
void CCustToolBar::OnCustHelp(NMHDR* pNMHDR, LRESULT* /*pResult*/)
{
#ifdef DEBUG
TRACE(_T("{ Help ID = %d }\n"), pNMHDR->idFrom);
#else
UNREFERENCED_PARAMETER(pNMHDR);
#endif
}
it would be a clean way to avoid the warning in Release mode while keeping the intended functionality for Debug.
Upvotes: 1