In C++ sometimes a variable will be defined, but not used. Here's an example - a function for use with COM_INTERFACE_ENTRY_FUNC_BLIND
ATL macro:
HRESULT WINAPI blindQuery( void* /*currentObject*/, REFIID iid, void** ppv, DWORD_PTR /*param*/ )
{
DEBUG_LOG( __FUNCTION__ ); //DEBUG_LOG macro expands to an empty string in non-debug
DEBUG_LOG( iid );
iid; // <<<<<<<----silence compiler warning
if( ppv == 0 ) {
return E_POINTER;
}
*ppv = 0;
return E_NOINTERFACE;
}
In the above example iid
parameter is used with DEBUG_LOG
macro that expands into an empty string in non-debug configurations. So commenting out or removing the iid
variable name in the signature is not an option. When non-debug configurations are being compiled the compiler spawns a C4100: 'iid' : unreferenced formal parameter
warning, so in order to silence the warning the iid;
statement that is believed to be a no-op is added.
The question is the following: if we have any of the following declarations:
CSomeType variableName; //or
CSomeType& variableName; //or
CSomeType* variableName;
will the following statement in C++ code:
variableName;
be a no-op at all times independent of what CSomeType
is?