lucy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marvin Humphrey <>
Subject Re: [KinoSearch] 64-bit linux errors with t/core/032-string_helper.t
Date Tue, 19 Jan 2010 19:35:08 GMT
On Mon, Jan 18, 2010 at 09:53:47PM -0800, Eric Howe wrote:
> On 2010-01-18, at 21:05 , Marvin Humphrey wrote:
> [...]
> > It seems messed up that an unsigned type gets promoted to a negative signed
> > type when used as an array subscript.  You're not supposed to use "char" on
> > its own as an array subscript, because whether "char" is signed or unsigned is
> > implementation defined, but either "signed char" or "unsigned char" are
> > allowed.
> Arrays in C are just convenient notation for pointer arithmetic so array
> indices in C are not char, nor are they signed char nor unsigned char,
> they're probably int. Are you getting tripped up by an implicit "a[(int)i]"
> cast on the index?
> Just a wild guess.

GCC will warn under -Wchar-subscripts (enabled by -Wall) if you use a naked
"char" variable as an array subscript.  It won't warn under either "signed
char" or "unsigned char", because those are both unambiguous.  That's what I
was referring to; it was imprecise of me to use "supposed to" and "allowed"
because it's the compiler rather than the C standard that imposes the
restriction, and it's only a warning not an error.

I'm still not sure exactly what's going on.  If it's just promotion, an int
should be wide enough to hold all the values of an unsigned char, so the
converted value should be the same.  So should values converted to whatever
64-bit type is used internally to perform pointer math on this system.

I think the next step is to isolate the behavior of this platform in a minimal
test app.  Peter, what output do you see when you run the program below?

Marvin Humphrey

#include <stdio.h>

unsigned char numbers[256];

static void
check_subscript(unsigned char subscript)
    if (subscript == numbers[subscript]) {
        printf("ok - %d == %d\n", subscript, numbers[subscript]);
    else {
        printf("not ok - %d == %d\n", subscript, numbers[subscript]);

int main ()
    int i;

    for (i = 0; i < 256; i++) {
        numbers[i] = i;


    return 0;

View raw message