Ethereal-dev: Re: [Ethereal-dev] gcc warnings about unused variables

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxx>
Date: Fri, 15 Feb 2002 15:57:29 -0800
On Sat, Feb 16, 2002 at 10:06:51AM +1100, Hamish Moffatt wrote:
> On Fri, Feb 15, 2002 at 04:34:48PM +0100, Joerg Mayer wrote:
> > +  CFLAGS="-D_U_=\"__attribute__((unused))\" $CFLAGS"
> > 
> > and this is, how it looks when there is an unused variable:
> > 
> >  static void
> > -capture_stop_cb(GtkWidget *w, gpointer data) {
> > +capture_stop_cb(GtkWidget *w _U_, gpointer data) {
> >    loop_data *ld = (loop_data *) data;
> 
> Will this work with Visual C++, used to build on Windows?

Yes, as long as we forcibly define _U_ to be an empty string when
building with Visual C++ (and when building with other non-GCC
compilers, on UNIX), and as long as _U_ isn't defined elsewhere (e.g. 
by some Windows header file), as that'll make _U_ expand to nothing, so
it'll be

	capture_stop_cb(GtkWidget *w , gpointer data) {

which is OK.

> Can a function have multiple unused arguments?

Yes:

	hostname$ cat foo.c
	int
	foo(int a _U_, int b _U_, int c)
	{
		return c + 17;
	}
	hostname$ gcc -D_U_= -c -O2 -Wall -W foo.c
	foo.c: In function `foo':
	foo.c:2: warning: unused parameter `a'
	foo.c:2: warning: unused parameter `b'
	hostname$ gcc -D_U_="__attribute((unused))" -c -O2 -Wall -W foo.c
	hostname$ gcc --version
	2.95.1f