Continue to Site

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.

#define Command Problems

Status
Not open for further replies.

amirm2039

Newbie level 6
Joined
Sep 13, 2014
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
89
Hi,
Could you give me an explanation of below code, please?

1: #define M1 "Y X.2"
2: #define M2 (20000000L)
3: #define M3(p) *((unsigned char *)(& p))
4: #define M4(d,s) F1((d),(const char *)(s))
5: #define M5(d,s) F2((d),(const far rom char *)(s))
5: #define M6(t,n) typedef int n

Best, Thanks
 

You make no mention of what language it is or which assembler/compliler/editor or compositor it is for. I am assuming it is 'C':

#define just forces a text substitution where the pre-processor finds it. The '#defined' first parameter is expanded to the second and subsequent parameters.

1: substitutes the text "Y X.2" when you use M1
2: makes M2 equal to the long number 20000000
3: Makes M3(your value) expand to a pointer to the unsigned char cast to a pointer to (your value) address.
4: Makes M4(first value, second value) into whatever F1(first value),constant pointer to (second value) means. F1 must itself be defined somewhere else.
5: Same as 4 except this time the pointer is to rom and probably at a high address. It would be device dependant.
Second 5: A strange one but I assume M6 expands to 't' being the new typedef name and 'n' becoming a new int with name 'n'.

In short, the define is expanded so keyword are retained but parameters passed between ( and ) are substituted for their equivalent names within the definition.

Brian.
 
THANKS SO MUCH.

That's right, it is for C language.
I'm so sorry about my mistakes.
thanks again!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top