From owner-freebsd-hackers@freebsd.org Mon Jan 1 15:54:53 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5FADAEAFE20 for ; Mon, 1 Jan 2018 15:54:53 +0000 (UTC) (envelope-from markmi@dsl-only.net) Received: from asp.reflexion.net (outbound-mail-210-135.reflexion.net [208.70.210.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0B5BC715B5 for ; Mon, 1 Jan 2018 15:54:52 +0000 (UTC) (envelope-from markmi@dsl-only.net) Received: (qmail 25503 invoked from network); 1 Jan 2018 15:48:05 -0000 Received: from unknown (HELO mail-cs-01.app.dca.reflexion.local) (10.81.19.1) by 0 (rfx-qmail) with SMTP; 1 Jan 2018 15:48:05 -0000 Received: by mail-cs-01.app.dca.reflexion.local (Reflexion email security v8.40.3) with SMTP; Mon, 01 Jan 2018 10:48:05 -0500 (EST) Received: (qmail 3495 invoked from network); 1 Jan 2018 15:48:05 -0000 Received: from unknown (HELO iron2.pdx.net) (69.64.224.71) by 0 (rfx-qmail) with (AES256-SHA encrypted) SMTP; 1 Jan 2018 15:48:05 -0000 Received: from [192.168.1.25] (c-76-115-7-162.hsd1.or.comcast.net [76.115.7.162]) by iron2.pdx.net (Postfix) with ESMTPSA id 814D1EC8FD9; Mon, 1 Jan 2018 07:48:04 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? From: Mark Millard In-Reply-To: <69781.1514800992@critter.freebsd.dk> Date: Mon, 1 Jan 2018 07:48:03 -0800 Cc: "Rodney W. Grimes" , FreeBSD Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <510305A9-460C-407F-B2FC-3521A6E1D78B@dsl-only.net> References: <201801010305.w0135luG084158@pdx.rh.CN85.dnsmgr.net> <559541DD-3287-4473-B7DE-B4DDC6860DF7@dsl-only.net> <69781.1514800992@critter.freebsd.dk> To: Poul-Henning Kamp X-Mailer: Apple Mail (2.3273) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Jan 2018 15:54:53 -0000 On 2018-Jan-1, at 2:03 AM, Poul-Henning Kamp = wrote: > -------- > In message <559541DD-3287-4473-B7DE-B4DDC6860DF7@dsl-only.net>, Mark = Millard wr > ites: >=20 >> "assert" indicates optional code, not required >> code. (This is despite its name.) >=20 > Assert statements are not debugging, although they greatly help > debugging, they are an integral part of the program, which documents > for the maintainers and the running system what assumptions are > being made. >=20 > Who ever added "#ifndef NDEBUG" not only failed Sensible Naming > 101, they also totally misunderstood the nature of assert() as > a programming construct. None of us invented assert as it was first historically created or as it is in the standards. It possibly predates pre-conditions, invariants, and the like (e.g., predicate transformers) as a programming technique. You are arguing with a definition we are not in control of if the standard's header is used (in C or in C++). It clearly was invented to allow avoiding the performance consequences of the contained expression. That suggests that it was invented for debugging, like it or not. If one wants to use assert, then instead of: assert(close(fd) =3D=3D 0); use code like: close_status=3D close(fd); assert(close_stats=3D=3D0); to avoid the close disappearing if NDEBUG is defined. Just a different coding organization for that specific point to be addressed. (This does not deal with the potential consequences of use of abort() for assert failure, especially code targeting multiple environments.) I wrote earlier: "One could invent an alternate to assert under a related name". You wrote: "Define your own assert() macro." Other than possible confusions over if a long standing definition is in use or not, these can address the issues with assert. =3D=3D=3D Mark Millard markmi at dsl-only.net