(I am reading the GCC mailing list in digest mode)

On 3/9/19 10:58 PM, gcc-digest-h...@gcc.gnu.org wrote:


On Fri, 8 Mar 2019, Joel Sherrill wrote:

Can gcc report when the parameter name in a C prototype
does not match that used in the implementation?

int f(int x);

int f(int y) {...}
I think this would be normal and expected - an installed header would use
a reserved-namespace name for the parameter while the implementation uses
a non-reserved name that's more convenient for use within the
implementation.  (Thus anything like this would only be useful if it can
know that it's e.g. OK to have __y and y as the names, and some code no
doubt uses other such conventions relating the two names.)
I can appreciate that a warning like this is not for everyone.  But /I/ would like and use such a warning for my own code.
May I remind to all that this is a typical case for you writing a GCC plugin. You want a warning that few other people want, and that warning is tied to your particular coding style.

You could avoid that warning by avoid naming the parameters in your header files, so you would declare
int f (int /*x*/); in your header file.

You might want to get a warning, but since it is not of general use (as many explained, not using the same name in the header and in the implementation of a given function parameter makes a lot of sense in general, even if you dislike such as style) you really should consider writing your own GCC plugin for that purpose.

How to write such a GCC plugin is a different question, and should be asked as such.

Cheers.

--
Basile STARYNKEVITCH   == http://starynkevitch.net/Basile
opinions are mine only - les opinions sont seulement miennes
Bourg La Reine, France

Reply via email to