Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 May 2004 22:24:40 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Pawel Jakub Dawidek <pjd@freebsd.org>
Cc:        cvs-all@freebsd.org
Subject:   Re: cvs commit: src/sbin/kldstat kldstat.c
Message-ID:  <20040530215900.N1952@gamplex.bde.org>
In-Reply-To: <20040530081550.GC12007@darkness.comp.waw.pl>
References:  <200405282116.i4SLGin4067490@repoman.freebsd.org> <20040530081550.GC12007@darkness.comp.waw.pl>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 30 May 2004, Pawel Jakub Dawidek wrote:

> On Fri, May 28, 2004 at 02:16:44PM -0700, David Malone wrote:
> +> dwmalone    2004/05/28 14:16:44 PDT
> +>
> +>   FreeBSD src repository
> +>
> +>   Modified files:
> +>     sbin/kldstat         kldstat.c
> +>   Log:
> +>   Decide how much space we need to print a pointer using
> +>   sizeof(void *) rather than if __alpha__ is defined.
> [...]
> +> -#if defined(__alpha__)
> +> -#define	POINTER_WIDTH	18
> +> -#else
> +> -#define	POINTER_WIDTH	10
> +> -#endif
> +> +#define	POINTER_WIDTH	(sizeof(void *) > 4 ? 18 : 10)
>
> Why not just:
>
> #define	POINTER_WIDTH	(sizeof(void *) * 2 + 2)

Well, neither gives the width of a pointer; plain "sizeof(void *)" gives
the width of "void *" pointers but not necessarily others :-).

The pointer width here is actually the field width for printing with
%p, under the assumption that this is a constant.  %p actually gives
0x%x or 0x%lx format, and kldstat depends on the magic that the pointers
that it prints all have a bit in their highest nybble set so that their
printed width is always the maximum.  The assumption could be avoided
using the nonstandard format %*p (where the * is POINTER_WIDTH), but
I think it is better to not use %p.  Its enforced 0x just gets in the
way, and on 64-bit machines POINTER_WIDTH is too wide for most tables
(though not kldstat's).  Common leading 0xff's should probably be
stripped on 64-bit machines.  The width would then be data-dependent.

Bruce



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