cvs commit: src/sbin/kldstat kldstat.c

Bruce Evans bde at zeta.org.au
Sun May 30 05:24:45 PDT 2004


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


More information about the cvs-src mailing list