Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Explain me the meaning of this macro in C

Status
Not open for further replies.

afesheir

Member level 1
Joined
Feb 4, 2010
Messages
33
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Activity points
1,508
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

Advanced Member level 4
Joined
Aug 29, 2004
Messages
1,185
Helped
145
Reputation
290
Reaction score
40
Trophy points
1,328
Location
Egypt
Activity points
5,880
Re: help in C syntax

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

afesheir

Member level 1
Joined
Feb 4, 2010
Messages
33
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Activity points
1,508
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

Advanced Member level 4
Joined
Aug 29, 2004
Messages
1,185
Helped
145
Reputation
290
Reaction score
40
Trophy points
1,328
Location
Egypt
Activity points
5,880
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
Joined
Dec 15, 2009
Messages
6
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
C Franco-Chinois
Activity points
1,311
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top