Ravi Uday wrote:
Emmanuel Delahaye wrote:
<snip>
Note that
#define ARRAY_BASE 0x1000
ARRAY_BASE[x];
is not C either because an integer and a pointer are different animals.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
But this does -
#define ARRAY_BASE 1000
and access it, such as
ARRAY_BASE[x] = <value>;
perhaps a typo in O.P code !
No, that is invalid for the reason Emmanuel Delahaye stated above.
Integers and pointers are not the same thing. All you have done is
change the value of the integer from 1000 hex to 1000 decimal probably
making it even worse.
The "correct" code if your system has something at address 1000 hex that
you are both allowed to access as an array of some_type and want to so
access would be
#define ARRAY_BASE ((some_type *)0x1000)
ARRAY_BASE[x];
This invokes undefined behaviour, however things like this are not too
uncommon in embedded systems where you have a memory mapped hardware
device you want to access.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.