Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Jan 2002 19:17:50 -0600
From:      "Jacques A. Vidrine" <n@nectar.cc>
To:        chuck rouillard <chuckr@opus.sandiegoca.ncr.com>
Cc:        Garrett Wollman <wollman@khavrinen.lcs.mit.edu>, freebsd-standards@FreeBSD.ORG
Subject:   Re: pathchk
Message-ID:  <20020201011750.GB91199@madman.nectar.cc>
In-Reply-To: <20020131135842.A96280-100000@opus.sandiegoca.ncr.com>
References:  <200201302216.g0UMG1Y64367@khavrinen.lcs.mit.edu> <20020131135842.A96280-100000@opus.sandiegoca.ncr.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Jan 31, 2002 at 03:27:16PM -0800, chuck rouillard wrote:
> On Wed, 30 Jan 2002, Garrett Wollman wrote:
> > I am of the opinion that it is silly.  Other reasonable people
> > disagree.  (I happen to think that their reasons for disagreement are
> > the result of inadequate tools, and the appropriate response is to fix
> > the tool, not kluge up the source code.)
> 
> Agreed, but given the number such casts currently
> peppered about in the source tree, and maybe some
> of the recent arguments for __P() on -arch, should
> this practice be continued?
> 
> I wouldn't mind hearing additional comments on
> this topic since I have other things I'd like
> contribute.

Just a personal opinion, but:

If a function returns a value that is useful, but you consciously
choose to ignore it, I find the `(void)' cast a welcome indicator of
that conscious decision.  For example, whenever I see code using
snprintf(), I always examine what is being done with the return value
--- the return value is typically used to detect truncation or advance
an offset within a buffer.  The difference between these two pieces of
code:

    snprintf(buf, "%x%y%z%z%y\a\a\n", foo, bar, baz, baz, bar);
 and
    (void)snprintf(buf, "%x%y%z%z%y\a\a\n", foo, bar, baz, baz, bar);

is that I don't have to wonder whether truncation was considered,
particularly if I wrote the code in question :-)


I don't mind the cast on functions where the return value is usually
useless (i.e. fprintf), but I don't generally use them myself.

Cheers,
-- 
Jacques A. Vidrine <n@nectar.cc>                 http://www.nectar.cc/
NTT/Verio SME          .     FreeBSD UNIX     .       Heimdal Kerberos
jvidrine@verio.net     .  nectar@FreeBSD.org  .          nectar@kth.se

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




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