Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Jan 2005 14:05:13 +0100
From:      Jens Schweikhardt <schweikh@schweikhardt.net>
To:        Thomas Dickey <dickey@radix.net>
Cc:        freebsd-current@freebsd.org
Subject:   Re: gratuitous gcc warnings: unused function arguments?
Message-ID:  <20050122130513.GB1951@schweikhardt.net>
In-Reply-To: <20050116193757.GA10974@saltmine.radix.net>
References:  <Pine.NEB.3.96L.1050116120744.50371A-100000@fledge.watson.org> <20050116144113.GB66854@gothmog.gr> <41EAB5FE.30603@freebsd.org> <20050116193757.GA10974@saltmine.radix.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050122130513.GB1951>