Paul Eggert wrote:
> > Do we need the compiler to verify that the parameter is really unused?
> > No, we don't. Even if the code is later refactored in such a way that
> > the parameter gets used, there is no damage.
> ...
> I see several things going on here. First, it's useful to glance at a 
> function F's head and see whether F's arguments are really needed, or 
> simply pacify an API. MAYBE_UNUSED doesn't tell me that; UNNAMED does.

Yes, but in doing that, it's first of all more useful to know what a
parameter is about. It would be *horrible* to have a function defined as

  void window_size_changed (int, int, int w, int)
  { ... }

It is much better to not omit the identifier:

  void window_size_changed (int /*x*/, int /*y*/, int w, int /*h*/)
  { ... }

or

  void window_size_changed (_GL_UNUSED_PARAMETER int x, _GL_UNUSED_PARAMETER 
int y,
                            int w, _GL_UNUSED_PARAMETER int h)
  { ... }

or

  void window_size_changed (int _GL_UNNAMED (x), int _GL_UNNAMED (y),
                            int w, int _GL_UNNAMED (h))
  { ... }

> Second, not everyone agrees about whether and when unused parameters 
> should be diagnosed and/or unnamed.

This is mostly because unused parameters arise from different situations:
  - as implementations of a function type / API,
  - or from refactorings and bitrot.

> Also witness C++, where a core guideline is "Unused parameters should be 
> unnamed" 
> <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#rf-unused>.

You must be joking? I can't take a style guideline from Bjarne Stroustrup
seriously. That is the guy who invented the syntax " = 0 " to denote an
unimplemented method and the parentheses syntax for the initializer of a
variable.

> I found many 
> arguments that were formerly used in old Emacs versions but the code had 
> bitrotted. The patch to fix this, which I have not applied yet, is over 
> 4000 lines long; it does not use MAYBE_UNUSED or UNNAMED, but simply 
> omits arguments.

I hope it does not omit the identifiers? That would be horrible, see
above.

> That project of using -Wunused-parameter in Emacs unfortunately also 
> resulted in many false positives.

Maybe we should have a way to declare that a function is meant to be an
implementation of a function type / API ?

Bruno




Reply via email to