Date: Fri, 17 Aug 2001 01:16:37 +1000 (EST) From: Bruce Evans <bde@zeta.org.au> To: Mark Murray <mark@grondar.za> Cc: <arch@FreeBSD.ORG> Subject: Re: Style 9 nitpicking question Message-ID: <20010817005031.S29341-100000@besplex.bde.org> In-Reply-To: <200108161010.f7GAAsK68419@grimreaper.grondar.za>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 16 Aug 2001, Mark Murray wrote:
> A piece of style(9) says:
>
> <manpage_extract name=style sect=9>
>
> static void
> usage()
> {
> /* Insert an empty line if the function has no local variables. */
>
> Use printf(3), not fputs/puts/putchar/whatever; it's faster and usually
> cleaner, not to mention avoiding stupid bugs.
>
> [ snip ]
>
> "usage: f [-aDde] [-b b_arg] [-m m_arg] req1 req2 [opt1 [opt2]]\n"
> "usage: f [-a | -b] [-c [-dEe] [-n number]]\n"
>
> (void)fprintf(stderr, "usage: f [-ab]\n");
> exit(EX_USAGE);
> }
>
> </manpage_extract>
>
> Questions:
>
> 1) That "(void)" is useless by any metric that I am able to determine
> (WARNS=2, BDECFLAGS etc), and gets in the way of linting. Is there
> any reason to continue to advocate its use by this example? There
> is no other reference to "voiding-out" of return values.
It by prevents warnings like the following from `lint -h':
"snprintf returns a value which is sometimes ignored"
"snprintf returns a value which is always ignored"
This is the opposite of getting in the way of linting.
> 2) Is this (fprintf(stderr, "...", ...); exit(n);) really better than
> errx(1, "...", ...); ?
Yes. The former is more portable, and prints the program name in the
usual place (after "usage: ").
> Any objections to changing the
>
> (void)fprintf(stderr, "usage: f [-ab]\n");
> exit(EX_USAGE);
>
> to
>
> errx(EX_USAGE, "usage: f [-ab]\n");
Yes :-). The second form here has the additional bug of printing the
program name twice (perhaps different names if the binary is linked).
Bruce
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010817005031.S29341-100000>
