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

Bug in debugger or compiler?

I have a slight problem with the following code:

unsigned char code * code x[] = {"a", "b", "c"};

void main() {

	unsigned char a;

	for(;;) a = x[0][0];
}

The device used is the Philips 8xC51MB2. After building it and starting a debug session with a and x[0][0] in the watch window, I find that although the variable a takes on the value of 0x61 in the endless loop, x[0][0] always shows the value zero.

When I change the device to some other device such as the Philips 8xC52, x[0][0] shows the correct value of 0x61.

Can anyone else verify this and let me know if it is a bug with the debugger or the compiler?

Thanks.

  • I have found that sometimes the watch window can give misleading information and this turns out to be due to optimisation. It may be that some optimisation is possible with the Philips 8xC51MB2 that is not possible with the 8xC52.

    You may have to study the acual assembly code to see if this is the case. Try lowering the level of optimisation to see if that makes any difference.

  • The compiler is quite likely to have optimised your code: you assign values to 'a' in the loop, but never use those values - therefore the compiler considers this to be "dead" code, and removes it!

    Try making 'a' volatile