Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Visual C++: Warning C4100

📅 2010-Aug-30 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

Warning 4100: unreferenced formal parameter might appear when C++ code is compiled at Warning Level 4 (/W4) with the Visual C++ compiler. For example, a function that generates C4100:

void Foo::OnEvent( const FooEvent& event )
{
    return;
}

There are a few ways to deal with this warning:

void Foo::OnEvent()
{
    return;
}
void Foo::OnEvent( const FooEvent& )
{
    return;
}
void Foo::OnEvent( const FooEvent& /* event */ )
{
    // Some commented code that uses "event" parameter
    return;
}
#pragma warning( push )
#pragma warning( disable: 4100 )
void Foo::OnEvent( const FooEvent& event )
{
    return;
}
#pragma warning( pop )
// Foo.cpp
#pragma warning( disable: 4100 )  // Disable for entire source file Foo.cpp

void Foo::OnEvent( const FooEvent& event )
{
    return;
}

A final note: Visual C++ 2010 does not seem to have this warning at all! It has been mysteriously removed without providing any reason.