#2111 (n * 1) returns only lower byte when added to pointer

closed-duplicate
5
2013-05-25
2012-11-26
Jan Rejlek
No

In the following function only the lower byte of the product (n * 1) is added to the pointer.
Command: sdcc -c test.c
Version: 3.2.0 #8008 (Jul 6 2012) (MINGW32)

__xdata struct {
int i[1000];
} s;

unsigned char test(unsigned n)
{
unsigned char b1, b2;

b1 = *((unsigned char*)&s + (n * 1)); // this compiles bad
b2 = *((unsigned char*)&s + n); // this compiles OK
return b1 + b2;
}

Discussion

  • Jan Rejlek

    Jan Rejlek - 2012-11-26

    sample code

     
  • Erik Petrich

    Erik Petrich - 2012-11-27
    • labels: --> common target code generation
    • milestone: --> fixed
    • assigned_to: nobody --> epetrich
    • status: open --> closed-duplicate
     
  • Erik Petrich

    Erik Petrich - 2012-11-27

    Thanks for the detailed report, but this has already been fixed in 3.2.1 #8098 (and later). If you don't want to wait for the next major release, you can download recent versions from the daily snapshot page.

     

Log in to post a comment.