Explain me the meaning of this macro in C

Status
Not open for further replies.

afesheir

Member level 1
hello friends ..
I can't understand the meaning of this marco:

Code:
#define ReadL( a, f) *(unsigned short*)(a+f)+(( *(unsigned short*)(a+f+2)) < < 16)

and this is a use of it;

Code:
psize = ReadL( buffer, 0x1CA);

can any body help ..?

I have posted this question in microcontroller section but I got no answer from friends there ..

amraldo

Re: help in C syntax

ReadL(a,f) is equivalent to a[f] + a[f+2] * 2^16
--
Amr

afesheir

Member level 1
help in C syntax

thx .. but kindly tell me how did u know that a is an array ..?? and how did u know that the notation >> means power of two ??

amraldo

Re: help in C syntax

There are some good C programming books like C by Example or Writing Bug Free C Code. They are of great help. I learned C from them.
--
Amr

notius

Newbie level 4
help in C syntax

1)
<< is Bitwise left shift,
>> is Bitwise right shift,
so it looks like multiplication by power of two.

2)
with those good books, you can find the information between arrays and pointers.

for example,

this two expressions:

a[f]
*(a+f)

are equal in some case.

3)
in your macro " *(unsigned short*)(a+f) "

(unsigned short*)

is a typecasting,

it lets the data associate with the pointer to be "unsigned short", so the operation a+f can be correctly done.

with 1),2),3) you can find the meaning for your macro.

enjoy the summer and enjoy your programming!

-- notius

Status
Not open for further replies.

Replies
16
Views
2K
Replies
3
Views
1K
Replies
3
Views
1K
Replies
6
Views
2K
Replies
1
Views
2K