tags:

views:

67

answers:

6

Anyone can explain in details what the following macro does?

#define write_XDATA(address,value) (((char *)0x010000) [address]=value)

thx!

+2  A: 

It assigns value to the byte at memory location 0x10000 + address. It's easier to grok if you separate it out a bit:

char* buf = (char *)0x010000;
buf[address]=value;

(Though of course you have no choice but to mash it all together in a macro.)

Marcelo Cantos
Not necessarily. Why could you not write a function that accepts a `char` and a `size_t` and writes that `char` at address 0x010000 + size_t?
sharptooth
Sorry, my last statement was ambiguous. What I meant was, "...in a macro, you have no choice...".
Marcelo Cantos
A: 

It maps addresses to real addresses using an offset and then writes to it. XDATA is probably a term taken over from the 8051-processor.

stefaanv
+6  A: 

You use it:

write_XDATA( Address, Value );

and it is expanded:

((char*)0x010000)[Address]=Value;

which is equivalent to the following:

char* baseAddress = (char*)0x010000;
*(baseAddress + Address) = Value;

so basically it writes a byte stored in Value at the address 0x010000 + Address.

sharptooth
A: 

I don't know how much details you want to hear, but the macro expands itself to what you have just written -

macro parameters address and value are put into address and value placeholders in the macro expansion definition (((char *)0x010000) [address]=value)

Axarydax
A: 

This macro on address + 0x010000 saving one byte of value.

Svisstack
+1  A: 

That's most probably part of a program designed to run on an embedded platform. It's used to do memory mapped IO.

The base address of the register-map is 0x010000. It writes value to the memory location 0x010000+address.

The use of the square brackets [] works because of the equivalence of array-addressing and pointer arithmetic in C.

edgar.holleis