From owner-freebsd-current@FreeBSD.ORG Sun Jan 16 14:41:34 2005 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 55D5D16A4D3; Sun, 16 Jan 2005 14:41:34 +0000 (GMT) Received: from kane.otenet.gr (kane.otenet.gr [195.170.0.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8858E43D1F; Sun, 16 Jan 2005 14:41:33 +0000 (GMT) (envelope-from keramida@freebsd.org) Received: from gothmog.gr (patr530-a016.otenet.gr [212.205.215.16]) j0GEfKZj010868; Sun, 16 Jan 2005 16:41:27 +0200 Received: from gothmog.gr (gothmog [127.0.0.1]) by gothmog.gr (8.13.1/8.13.1) with ESMTP id j0GEfDcX067035; Sun, 16 Jan 2005 16:41:13 +0200 (EET) (envelope-from keramida@freebsd.org) Received: (from giorgos@localhost) by gothmog.gr (8.13.1/8.13.1/Submit) id j0GEfDwX067034; Sun, 16 Jan 2005 16:41:13 +0200 (EET) (envelope-from keramida@freebsd.org) Date: Sun, 16 Jan 2005 16:41:13 +0200 From: Giorgos Keramidas To: Robert Watson Message-ID: <20050116144113.GB66854@gothmog.gr> Mail-Followup-To: freebsd-current@freebsd.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: cc: freebsd-current@freebsd.org Subject: Re: gratuitous gcc warnings: unused function arguments? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Jan 2005 14:41:34 -0000 On 2005-01-16 12:18, Robert Watson wrote: > At some point in the relatively recent past, we began to generate > warnings for unused arguments in function definitions. This is a > fairly irritating practice, as it interacts poorly with function > implementations plugged into pluggable function interfaces, such as > PAM, main(), etc. Here's an example of a particularly irritating > instance of the warning: > > static void > usage(void) > { > > fprintf(errno, "program: too many arguments\n"); > exit(-1); > } > > int > main(int argc, char *argv[]) > { > > if (argc != 1) > usage(); > > dostuff(); > } In this case, using __unused is a GCC-specific but commonly used way to specify that argv is unused and we know it's ok. There is also a more portable way to specify within the body of the function that argv is unused: % int % main(int argc, char *argv[]) % { % % (void)argv; % if (argc != 1) % usage(); % return (0); % } This allows the main() function to keep being compliant with the ANSI standard that specifies only two valid prototypes for main(): int main(void); int main(int argc, char *argv[]); But it also inhibits the warning from GCC, because argv is 'used', even though the value of the void expression is immediately thrown away. I'm not sure if this is "better" than __unused, but it works both on GCC and on the Forte C/C++ compilers of Sun that I've tried it with. - Giorgos