2

What is the reason for issuing "unreferenced formal parameter" warning? In an existing SO post this warning is explained to be useful for drawing the attention of the programmer to the function (in case he forgot to do some operations with the parameter) and also useful for code maintenance (to signal to future developers that the parameter was not omitted, but was purposely left out). Apart from style concerns, why does the programmer want to be warned against unused parameters? Are such parameters copied, if passed by value?

void myFunction(int param) {
}
Community
  • 1
  • 1
Pavlo Dyban
  • 1,297
  • 2
  • 15
  • 28
  • 1
    If it is pass by value, they are copied. – Mahesh Mar 16 '12 at 11:54
  • You can get rid of `param`, so you're just left with `void myFunction(int)`, although this can be confusing. Sometimes you'll see commented out parameters `void myFunction(int /*param*/)`, but I'm loath to use C style comments in a C++ codebase. – Peter Wood Mar 16 '12 at 12:50

2 Answers2

3

To prevent possible distractions (forgetting to use the parameter) and to strive for a more maintainable code are reasons enough.

The possible performance hit of unused parameters being copied is an additional reason, but not the main one.

Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
1

While it is not specified, I'd wager that omitting the parameter name in the function definition does not change any binary code.

Compilation units that have only the declaration of the function available will not know whether to copy the parameter. Other compilation units can apply normal optimization to the function call, and any optimizer worth any salt will discover that the parameter is dead right at the start of the function.

Thus, I wouldn't worry about performance here. The pure reason is readability.

thiton
  • 35,651
  • 4
  • 70
  • 100