[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-standards
Subject:    Re: pathchk
From:       "Jacques A. Vidrine" <n () nectar ! cc>
Date:       2002-02-01 1:17:50
[Download RAW message or body]

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
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic