This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

array index type of signed int

Hi list,

i'm working with c51v750a. My problem:

int array[ 0] _at_ 0x7600; //xdata
unsigned char index = 0; //xdata

printf("%d", &array[ index]);
printf("%d", &array[(unsigned char)(index - 1)]); //what is wrong?

// Result:
// 30208 --> 0x7600 (correct)
// 30206 --> 0x75FE == array[ -1] incorrect, // expected array[255] @ 0x77FE

I've read in Compiler's changelog [v7.50] that there was a fix for array with signed int index.

I don't need a workaround, but this seems like a compiler-bug. Or is my "logic" incorrect?

Thanks in advance,
Lars

Parents
  • What exactly are you trying to achieve here?

    Is this some competition to use as many bizarre tricks in one go as possible?!

    * Arrays of size zero
    * negative array indexes (ie, attempting to access elements before the start of the array)
    * using a negative index, but then casting it to signed and relying on it coming out as positive 255!

    If you want to access X:0x76FF, why don't you just do it?

    Or, if you want an index of 255, why don't you just do it - instead of obfuscating it with a cast of -1 ?!

    I think the compiler might feel entitled to behave a little oddly in the face of such tactics!

Reply
  • What exactly are you trying to achieve here?

    Is this some competition to use as many bizarre tricks in one go as possible?!

    * Arrays of size zero
    * negative array indexes (ie, attempting to access elements before the start of the array)
    * using a negative index, but then casting it to signed and relying on it coming out as positive 255!

    If you want to access X:0x76FF, why don't you just do it?

    Or, if you want an index of 255, why don't you just do it - instead of obfuscating it with a cast of -1 ?!

    I think the compiler might feel entitled to behave a little oddly in the face of such tactics!

Children