Is this a BUG?

In C51 v8.01 Compiler
void Fnc(BYTE * pT, WORD Dat, BYTE x, BYTE y)
{
BYTE Asc[6];
BYTE * pSource = Asc + 5 - (x + y);
.....
}

I got wrong "pSource", but it is OK in v7.50
I changed it to

BYTE * pSource = &Asc + 5 - (x + y);

It is OK, WHY?

Parents
  • BYTE Asc[6];
    BYTE * pSource = Asc + 5 - (x + y);
    I got wrong "pSource",

    That's a completely useless description of what you see. What did you actually get as pSource? What did you expect to get instead, and why?

    The two ways of initializing pSource you show must yield different results in a correct C compiler. Which means neither of them is "correct" in and of itself --- it depends on what you wanted this code to do, but you didn't tell us what that is.

Reply
  • BYTE Asc[6];
    BYTE * pSource = Asc + 5 - (x + y);
    I got wrong "pSource",

    That's a completely useless description of what you see. What did you actually get as pSource? What did you expect to get instead, and why?

    The two ways of initializing pSource you show must yield different results in a correct C compiler. Which means neither of them is "correct" in and of itself --- it depends on what you wanted this code to do, but you didn't tell us what that is.

Children
More questions in this forum