I have the following code:
int some_array[256] = { ... };
int do_stuff(const char* str)
{
int index = *str;
return some_array[index];
}
Apparently the above code causes a bug in some platforms, because *str can in fact be negative.
So I thought of two possible solutions:
Casting the value on assignment (
unsigned int index = (unsigned char)*str;
).Passing
const unsigned char*
instead.
Edit: The rest of this question did not get a treatment, so I moved it to a new thread.