Re: gratuitous gcc warnings: unused function arguments?

From: Jens Schweikhardt <schweikh_at_schweikhardt.net>
Date: Sat, 22 Jan 2005 14:05:13 +0100
On Sun, Jan 16, 2005 at 02:37:57PM -0500, Thomas Dickey wrote:
# On Sun, Jan 16, 2005 at 10:44:14AM -0800, Tim Kientzle wrote:
# > Giorgos Keramidas suggested:
# > >
# > >%      (void)argv;
# > 
# > I first saw this idiom for marking unused
# > arguments over 10 years ago and have used
# > it extensively since then.  Very portable;
# > highly recommended.
# 
# except of course for the compilers that warn about no effect...

All compilers I have used (which includes embedded compilers) would warn
about "no effect" only for

	argv;

but shut up for

	(void)argv;

The most portable solution involves some redundancy, e.g. simply
using all args. May look ugly to some eyes and may be outright
confusing for ten arg functions where you only "use" the last one.

	if (argc != 1 || argv[1] != 0) { ... }

and variations thereof. Note that argc != 1 catches the "impossible"
case of argc == 0.

On a more philosophical note, it could be argued that a function using
its second arg implicitly uses its first arg :-)

Regards,

	Jens
-- 
Jens Schweikhardt http://www.schweikhardt.net/
SIGSIG -- signature too long (core dumped)
Received on Sat Jan 22 2005 - 12:05:34 UTC

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