[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gnulib] [bug-gnulib] fts portability fix for hosts with unusual

From: Bruno Haible
Subject: Re: [bug-gnulib] [bug-gnulib] fts portability fix for hosts with unusual pointer semantics
Date: Mon, 9 May 2005 22:04:34 +0200
User-agent: KMail/1.5

Paul Eggert wrote:
> That reminds me; fts.c violates C89 in a couple of places, which could
> lead to core dumps on unusual hosts where void * and FTSENT const **
> have differing runtime representations.  I installed this patch into
> coreutils.
> +static int
> +fts_compar (void const *a, void const *b)
> +{
> +  /* Convert A and B to the correct types, to pacify the compiler, and
> +     for portability to bizarre hosts where "void const *" and "FTSENT
> +     const **" differ in runtime representation.  The comparison
> +     function cannot modify *a and *b, but there is no compile-time
> +     check for this.  */
> +  FTSENT const **pa = (FTSENT const **) a;
> +  FTSENT const **pb = (FTSENT const **) b;
> +  return pa[0]->fts_fts->fts_compar (pa, pb);
> +}

The cost of an extra function call per comparison is pretty high, just
to get rid of a cast that will most likely never lead to any damage.
(I have not yet seen any platform where the ABI treats 'void *' pointers
differently than any data pointers. The basic reason that 'void *' exists
at all in C is to permit this kind of cast.)

Therefore I would conditionalize this extra function indirection with
or similar, so that it is disabled by default.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]