From: Michael Haggerty Date: Thu, 21 Sep 2017 07:42:35 GMT Subject: Re: [PATCH v2 02/21] prefix_ref_iterator: break when we leave the prefix Message-ID: <32b3d338-6781-a600-2c7e-65dc2818aab5@alum.mit.edu> In-Reply-To: On 09/20/2017 10:25 PM, Stefan Beller wrote: > On Mon, Sep 18, 2017 at 11:22 PM, Michael Haggerty wrote: >> [...] >> +/* Return -1, 0, 1 if refname is before, inside, or after the prefix. */ >> +static int compare_prefix(const char *refname, const char *prefix) >> +{ >> + while (*prefix) { >> + if (*refname != *prefix) >> + return ((unsigned char)*refname < (unsigned char)*prefix) ? -1 : +1; > > This looks interesting. > > We get a signed char* , cast it to unsigned char* and then > compare byte by byte. Not quite. We get a `char *` of unknown signedness (it's implementation-dependent), dereference it into a `char`, then cast that value to `unsigned char`. What you described would be *(const unsigned char *)refname < *(const unsigned char *)prefix But I assume that these two variants would result in identical assembly code. > [...] Michael