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

Want to know the difference

I want to know the differences between the following two definiations:

 (*((volatile char xdata *)( CHIP_BASE + i)))

 ((volatile char xdata *)( CHIP_BASE + PTR_BASE + PTR_SIZE * i))

Thank you.

Parents
  • "No, the first one "is" not a pointer --- it only uses one as part of the computation."

    I'm afraid it *is* a pointer - one that is being dereferenced.

    "It actually is an object of type "volatile char xdata","

    The only object present in that expression is one of type 'volatile char xdata *'. Dereferencing that pointer object will yield the value of the object being pointed to, if indeed it *is* pointing to an object.

    "As such, it's equivalent to something like

    volatile char xdata chip[] _at_ CHIP_BASE;
    /*...*/
    chip[i]"

    That is badly wrong.

Reply
  • "No, the first one "is" not a pointer --- it only uses one as part of the computation."

    I'm afraid it *is* a pointer - one that is being dereferenced.

    "It actually is an object of type "volatile char xdata","

    The only object present in that expression is one of type 'volatile char xdata *'. Dereferencing that pointer object will yield the value of the object being pointed to, if indeed it *is* pointing to an object.

    "As such, it's equivalent to something like

    volatile char xdata chip[] _at_ CHIP_BASE;
    /*...*/
    chip[i]"

    That is badly wrong.

Children
  • I'm afraid it *is* a pointer - one that is being dereferenced.

    That makes no sense. By your reasoning, a wheel is a Porsche, just because it's part of its construction.

    We were talking about the expressions given by the OP. Not parts of them, or how those parts were used, but just the expressions as given. And I'm afraid I must insist that the first of them is not a pointer. The type of that expression as a whole is (volatile char xdata):

    (*((volatile char xdata *)( CHIP_BASE + i)))

    The thing in the emphasized parentheses is a pointer, but the expression as whole is not.

  • "I'm afraid it *is* a pointer - one that is being dereferenced.

    That makes no sense. By your reasoning, a wheel is a Porsche, just because it's part of its construction."

    It makes perfect sense. The line of code presented shows a pointer being dereferenced.

    Your analogy is amusing but irrelevant.

    "We were talking about the expressions given by the OP. Not parts of them, or how those parts were used, but just the expressions as given. And I'm afraid I must insist that the first of them is not a pointer. The type of that expression as a whole is (volatile char xdata)"

    Really? The OP asked:
    "I want to know the differences between the following two definiations:"

    Now, does that sound like 'what are the types of these expressions as a whole' to you?

    "The thing in the emphasized parentheses is a pointer, but the expression as whole is not."

    You're right - it is a *dereferenced* pointer.

  • Really? The OP asked:
    "I want to know the differences between the following two definiations:"

    Now, does that sound like 'what are the types of these expressions as a whole' to you?


    No, but the overall type most definitely is one of the "differences between the ... definitions" that he did ask about.

    The internal structure of both expressions does indeed involve pointers. But by no stretch of the imagination does that imply that "they are both pointers", as you wrote here in your first contribution to this thread. Of the two things covered by that word "they", only one actually is a pointer, the other only contains one. I really hope you don't seriously believe this to be a negligible difference.

  • "The internal structure of both expressions does indeed involve pointers. But by no stretch of the imagination does that imply that "they are both pointers", as you wrote here in your first contribution to this thread."

    Your snippage of context has altered the quote. What I wrote was:

    "No, they are both pointers. The difference is that the first one is being dereferenced."

    This was in response to the OP's assertion that the first was a variable.

    "Of the two things covered by that word "they", only one actually is a pointer, the other only contains one."

    Do you disagree that the first one is a dereferenced pointer?

    "I really hope you don't seriously believe this to be a negligible difference."

    Don't be silly.