This is a tiny project of about 2000LOC. It is being compiled with -Wall. Now, I tried adding -Wextra. Two things happened:

  • Some minor but valid warnings popped up, e.g. Comparing signed with unsigned
  • Some minor but false warnings popped up, e.g. Unused function parameter.

Those functions implement agreed-upon prototypes. But the extra parameters are really not needed for now.

However the unfixable warnings pollute the build log and could hide a much more dangerous warning.

Should the -Wextra be retained or removed? How can a compromise be made for the most robust code development in the future?

  • 3
    if you know the argument is unused then just add it in a (void)arg; statement, this is a noop and will document that you don't use it but stops the compiler from shooting warnings – ratchet freak Dec 4 '13 at 9:32
  • @ratchetfreak, please post this as an answer. – Vorac Dec 4 '13 at 9:33

nearly all warnings have workarounds to silence them in specific circumstances

  • the unsigned vs. signed comparison means you need to double check the types

  • unused parameter warnings can be silenced by adding a (void)arg; statement in the function, this is a noop and will document that the argument is unused

failing that you can surround the warning emitting code with #pragmas that disable and re-enable those warnings as needed

| improve this answer | |
  • Why does the noop workaround work? – Vorac Dec 4 '13 at 9:39
  • 3
    because it is idiomatic that it works for exactly this need (silence unused warnings)... – ratchet freak Dec 4 '13 at 9:42

There are several ways to get rid of those harmless warnings, without also disabling the useful ones.

  1. The -Wall and -Wextra warning options enable a whole bunch of warnings that can also be enabled/disabled individually. To avoid generating the 'unused parameter' warnings, you can use

    -Wall -Wextra -Wno-unused-parameter
  2. If it is only for a limited number of arguments in a limited number of functions that the 'unused parameter' warning is known to be spurious, you can suppress the warning on a case-by-case basis

    • Either by using the parameter, if only in a no-op statement like

    • Or, if you don't mind GCC-specific code, by adding the unused attribute to the relevant parameters

      void foo(int arg __attribute__((unused)) )
      { /* ... */ }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.