Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Feb 2002 18:45:15 -0500
From:      Mike Barcroft <mike@FreeBSD.ORG>
To:        Peter Dufault <dufault@hda.hda.com>
Cc:        FreeBSD-Standards <freebsd-standards@FreeBSD.ORG>
Subject:   Re: pathchk - review
Message-ID:  <20020219184515.G5526@espresso.q9media.com>
In-Reply-To: <20020219144756.A636@hda.hda.com>; from dufault@hda.hda.com on Tue, Feb 19, 2002 at 02:47:56PM -0500
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>

next in thread | previous in thread | raw e-mail | index | archive | help

--p4qYPpj5QlsIQJ0K
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Peter Dufault <dufault@hda.hda.com> 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 <stdlib.h>

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020219184515.G5526>