From owner-freebsd-standards Tue Feb 19 15:49:41 2002 Delivered-To: freebsd-standards@freebsd.org Received: from espresso.q9media.com (espresso.q9media.com [216.254.138.122]) by hub.freebsd.org (Postfix) with ESMTP id 8315237B402 for ; Tue, 19 Feb 2002 15:49:37 -0800 (PST) Received: (from mike@localhost) by espresso.q9media.com (8.11.6/8.11.6) id g1JNjFl77596; Tue, 19 Feb 2002 18:45:15 -0500 (EST) (envelope-from mike) Date: Tue, 19 Feb 2002 18:45:15 -0500 From: Mike Barcroft To: Peter Dufault Cc: FreeBSD-Standards Subject: Re: pathchk - review Message-ID: <20020219184515.G5526@espresso.q9media.com> References: <20020129210829.GC50337@madman.nectar.cc> <20020205232519.N7805-101000@opus.sandiegoca.ncr.com> <20020212170303.B55750@espresso.q9media.com> <20020217020217.GB46829@madman.nectar.cc> <20020217004339.J57687@espresso.q9media.com> <20020219144756.A636@hda.hda.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="p4qYPpj5QlsIQJ0K" Content-Disposition: inline In-Reply-To: <20020219144756.A636@hda.hda.com>; from dufault@hda.hda.com on Tue, Feb 19, 2002 at 02:47:56PM -0500 Organization: The FreeBSD Project Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --p4qYPpj5QlsIQJ0K Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Peter Dufault writes: > > The type is a pointer to a read-only string. The type he was really > > looking for was a read-only pointer to a read-only string: > > > > const char * const VARIABLE; > > > > But as I suggested, manifest constants are better. > > No, debuggers don't handle them well. "When possible, avoid the > preprocessor" IMHO. The same applies to magic numbers versus enums. Obviously what you're saying doesn't apply to the code in question. We will never need to debug fprint(3) or err(3) calls. Also, as Bruce pointed out in a private e-mail, atleast two of the variables should be string literals, since they are only used once. I also disagree with what you're saying in the general case. Things that are read-only aren't usually the things one is interesting in, when debugging. I've attached a sample program which uses the two forms discussed above. Are you able to differentiate them when you debug this program? I'm certainly not able to. Converting magic numbers is also pretty easy when you have the source. Here's what Peter van der Linden had to say about enum in his book, Expect C Programming: "In a weakly typed language like C, they provide very little that can't be done with a #define, so they were omitted from most early implementations of K&R C. But they're in most other languages, so C finally got them too." I'm going to get this code cleaned up and committed, since I think Chuck is no longer interested in it. Best regards, Mike Barcroft --p4qYPpj5QlsIQJ0K Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="sample.c" #include const char * const MYVAR = "test"; #define MYVAR2 "test2" static void myfunc(const char * const, const char * const); int main(void) { myfunc(MYVAR, MYVAR2); exit(0); } static void myfunc(const char * const arg, const char * const arg2) { abort(); } --p4qYPpj5QlsIQJ0K-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message