Re: gratuitous gcc warnings: unused function arguments?

From: Garance A Drosihn <drosih_at_rpi.edu>
Date: Sun, 16 Jan 2005 18:16:49 -0500
At 12:18 PM +0000 1/16/05, Robert Watson wrote:
>One of the reasons why I find __unused irritating is the
>following sort of situation:
>
>int
>dummyfunction(int arg1, int arg2, char *argv)
>{
>
>#ifdef DUMMY_USES_ARGV
>	if (argv != NULL)
>		printf("dummyfunction: %s\n", argv);
>#endif
>	return (arg1 + arg2);
>}
>
>With the new world order, we would have to ifdef the function
>definition to conditionally use __unused in order to allow the
>function to compile with or without the #ifdef.

In this specific case, would it make sense to change the code to be:

int
dummyfunction(int arg1, int arg2, char *argv)
{

	if (DUMMY_USES_ARGV && (argv != NULL))
		printf("dummyfunction: %s\n", argv);
	return (arg1 + arg2);
}

?

This does mean you must always define DUMMY_USES_ARGV to be 0 or 1
(which is easy enough to do by using an #ifndef check up at the start
of the file).  But it does remove the warning message (at least in gcc),
and in my testing it also seems to produce the same-size object-code
as the #ifdef version.

-- 
Garance Alistair Drosehn            =   gad_at_gilead.netel.rpi.edu
Senior Systems Programmer           or  gad_at_freebsd.org
Rensselaer Polytechnic Institute    or  drosih_at_rpi.edu
Received on Sun Jan 16 2005 - 22:16:51 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:26 UTC