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))
The first one has an extra * in it. The pointer will be "dereferenced", and thus the first line refers to an actual object (a char, a volatile xdata char, to be more precise). The second lacks the *, and so this object is a pointer-to-char type, not a char. There are of course the differences in the address calculated, which should be trivial. If these two expressions are part of a macro with a parameter i, then you might run into trouble with the expanded version of "i". In #define macros, it's a good idea always to wrap the parameters in a layer of parenthesis to make sure the precedence is correct.
#define CHIP_REG(i) (*((char *)(BASE + (i))))
Hi Drew Davis, Thank you for your sincere help. The first one is a varible. The second one is a pointer. Right?
"The first one is a varible. The second one is a pointer. Right?" No, they are both pointers. The difference is that the first one is being dereferenced. This is basic 'C' stuff so you really need to look in your 'C' book to familiarise yourself with the way pointers work.
Thank you. I will carefully read my book again.
View all questions in Keil forum