bug-grep
[Top][All Lists]
Advanced

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

Re: [PATCH] dfa: fix signedness warnings


From: Paul Eggert
Subject: Re: [PATCH] dfa: fix signedness warnings
Date: Fri, 21 May 2010 15:05:13 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4

On 05/21/10 00:20, Paolo Bonzini wrote:

> -      prepare_wc_buf (p, end);
> +      prepare_wc_buf ((const char *)p, end);

A better fix, in the long run anyway, is to remove the part of the code that
casts char * to unsigned char *, and to use char * uniformly.

The trick of casting char * to unsigned char * was originally put in there,
I expect, because circa-1990 compilers generated more efficient
code for *U, where U is of type unsigned char *, than they did for
((unsigned char) *S), where S is of type char *.  This is no longer
the case, so the trick isn't needed any more.

We can get rid of the casts by using a little function like this:

static inline unsigned char uc (char c) { return c; }

and then saying "uc (*S)" rather than "(unsigned char) *S".  This
is a bit safer than the cast, since it catches mistakes such as
when *S is itself a pointer.



reply via email to

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