From owner-cvs-all Thu Mar 7 3:54:45 2002 Delivered-To: cvs-all@freebsd.org Received: from mailhub.fokus.gmd.de (mailhub.fokus.gmd.de [193.174.154.14]) by hub.freebsd.org (Postfix) with ESMTP id AA41137B416; Thu, 7 Mar 2002 03:54:34 -0800 (PST) Received: from beagle (beagle [193.175.132.100]) by mailhub.fokus.gmd.de (8.11.6/8.11.6) with ESMTP id g27BsMR25060; Thu, 7 Mar 2002 12:54:27 +0100 (MET) Date: Thu, 7 Mar 2002 12:54:22 +0100 (CET) From: Harti Brandt To: Mike Barcroft Cc: Harti Brandt , "David O'Brien" , Mark Murray , , Subject: Re: cvs commit: src/usr.bin/rwall rwall.c In-Reply-To: <20020307063841.D81803@espresso.q9media.com> Message-ID: <20020307124800.S99061-100000@beagle.fokus.gmd.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, 7 Mar 2002, Mike Barcroft wrote: MB>Harti Brandt writes: MB>> The point of (void) is that the programmer who writes the code tells MB>> another programmer who reads the code: "Yes, I know, this function returns MB>> a value, but I ignore it and I know what I'm doing so don't be surprised." MB> MB>I always thought that explanation was rather silly. Why not just put MB>a comment at the top that says, "I realize I don't check every return MB>value, that is intentional." :) It is a common misconception, that programming is communication between a programmer and a computer. It is more relevant, that another programmer can read the code and understand it without. For easy understanding locality of the context is essential. When reading (void)func(...), I immediately see, that the return value is intentionally ignored. When there is a comment on top of the file saying 'the return value of func is sometimes ignored' I have to lookup that comment when I see func(...) (and I have to remeber that there was such a comment. I aggree however, that there is a class of functions like printf(), where one should have a general comment in his mind 'the return value of function printf is almost ever ignored'. snprintf is however not in this class, see your comment below... MB> MB>I did find the explanation I was looking for in MB>Message-ID: <20010817005031.S29341-100000@besplex.bde.org>: MB>: It by prevents warnings like the following from `lint -h': MB>: MB>: "snprintf returns a value which is sometimes ignored" MB>: "snprintf returns a value which is always ignored" MB>: MB>: This is the opposite of getting in the way of linting. MB> MB>> In the given case it is obvious that the snprintf shouldn't fail. MB> MB>In this case yes, in general snprintf()'s return value should always MB>be checked unless truncation is irrelevant. For cases in which MB>snprintf() can't fail, sprintf() is a good choice. Exactly. snprintf suggests to the reader of the code, that truncation or errors may happen and he wonders why one doesn't check the return code. harti -- harti brandt, http://www.fokus.gmd.de/research/cc/cats/employees/hartmut.brandt/private brandt@fokus.fhg.de To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message