Flagging unused function arguments

Petter Reinholdtsen pere at HUNGRY.COM
Mon Jan 24 03:53:43 EST 2005


In the process of fixing warnings, a large class of warnings are
unused arguments to functions.  A common way to fix this is to flag
unused argument as such, letting gcc now that these arguments are
supposed to be unused.  There are two parts to this method.  First, a
define in some common header file (normally config.h):

  /* Macro for declaring function arguments unused. */
  #if defined(__GNUC__)
  #  define UNUSED __attribute__((unused)) /* Flag variable as unused */
  #else /* not __GNUC__ */
  #  define UNUSED
  #endif

Next, one used this flag when a function is defined, flagging the
unused arguments:

  static int loadLabel(labelObj *label, mapObj *map UNUSED)
  {
     ...
  }

The flag can be placed in front of or after the variable.  Personally,
I prefer to place it after the variable.

My question is where I should put this define?  I notice there is no
config.h generated by configure (perhaps it should be changed?), so I
am trying to guess which of the other header files are fit for such
define.  Perhaps a new headerfile "common.h" is better?  Or perhaps
starting to generate "config.h" is the best option?  What do you
think?



More information about the mapserver-dev mailing list