gratuitous gcc warnings: unused function arguments?

Garance A Drosihn drosih at rpi.edu
Sun Jan 16 15:16:52 PST 2005


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


More information about the freebsd-current mailing list