1

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?

Vorac
  • 7,073
  • 7
  • 38
  • 58
  • 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 04 '13 at 09:32
  • @ratchetfreak, please post this as an answer. – Vorac Dec 04 '13 at 09:33

2 Answers2

3

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

ratchet freak
  • 25,706
  • 2
  • 62
  • 97
3

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

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

      void foo(int arg __attribute__((unused)) )
      { /* ... */ }
      
Bart van Ingen Schenau
  • 71,712
  • 20
  • 110
  • 179