From owner-freebsd-hackers Thu Mar 7 12:28: 1 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mail.rpi.edu (mail.rpi.edu [128.113.22.40]) by hub.freebsd.org (Postfix) with ESMTP id D873337B404 for ; Thu, 7 Mar 2002 12:27:55 -0800 (PST) Received: from [128.113.24.47] (gilead.acs.rpi.edu [128.113.24.47]) by mail.rpi.edu (8.12.1/8.12.1) with ESMTP id g27KRoKD115050; Thu, 7 Mar 2002 15:27:54 -0500 Mime-Version: 1.0 X-Sender: drosih@mail.rpi.edu Message-Id: In-Reply-To: <20020307071630.E26DBBA03@i8k.babbleon.org> References: <52204.1015480748@critter.freebsd.dk> <20020307071630.E26DBBA03@i8k.babbleon.org> Date: Thu, 7 Mar 2002 15:27:49 -0500 To: "Brian T.Schellenberger" From: Garance A Drosihn Subject: Re: RFC: style(9) isn't explicit about booleans for testing -- an actual analysis of the code! Cc: hackers@FreeBSD.ORG Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Scanned-By: MIMEDefang 2.3 (www dot roaringpenguin dot com slash mimedefang) Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG At 2:16 AM -0500 3/7/02, Brian T.Schellenberger wrote: >Maybe your brain has gotten used to it, but to us ordinary >mortals, even us ordinary mortals who've been slogging C >code for time periods that can be measured in decades >(yikes!), it is very tempting to read > > if (!strcmp(a,b,l)) > >as "if the strings don't compare" which, in ordinary usage, >means don't compare *equal*. But of course the C program >is going to proceed to do exactly the opposite of that. Okay, I will agree I have made that mistake a few times. Not often, but it really burns me up when I realize that's the source of some bug. So, that sounds like a good reason. >But *ALL* of this is beside the nominal point ANYWAY, which >is to discuss the proper wording for the man(9) style guide >which is supposed to document how things things are actually >done in the kernel, not personal preference. As to the wording, PHK suggested that the wording for this rule in style(9) be changed: - - - get rid of the word boolean, ie: change Do not use ! for tests unless it is a boolean, e.g. use to Do not use ! for tests unless it is an integer type, e.g. use - - - Dave O'Brien claimed the very same rule was *only* there to prevent "if (!strcmp(a,b))". May I suggest that we probably want two different rules? Change the current rule so it says 'integer type' instead of 'boolean' (which doesn't really exist in C anyway), and then add the rule about strcmp()? -- Garance Alistair Drosehn = gad@eclipse.acs.rpi.edu Senior Systems Programmer or gad@freebsd.org Rensselaer Polytechnic Institute or drosih@rpi.edu To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message