View previous topic :: View next topic |
Author |
Message |
Guest
|
Inquiry on C instruction shortcuts and Macro |
Posted: Fri Sep 24, 2004 9:23 pm |
|
|
Hello,
I am just curious when I read an ANSI-C books I found few instruction that uses shorcuts!!! a few examples listed below:
Code: |
#define max(a,b) ((a) > (b) ? (a) : (b))
Int1 They_Match;
They_Match = ((Buffer_0[0] == Buffer_1[0])
&& (Buffer_0[1] == Buffer_1[1])
&& (Buffer_0[2] == Buffer_1[2])
&& (Buffer_0[3] == Buffer_1[3])
&& (Buffer_0[4] == Buffer_1[4]));
|
Can someone explain this C shortcuts or macros? Is their a book or information that discusses all this shortcuts?
I'm just curios on this coz some books uses this instruction...
Thanx
[/code] |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Sep 25, 2004 5:37 am |
|
|
I have no clue as to what exactly your question is, can you give me another clue?
Do you want to know more about what macro's are? If yes, then call them by their name and don't call them 'shortcuts'.
Your first example is a macro, the second is just a line of normal C code.
General questions about the C language that have nothing to do with the CCS compiler or the PIC processor shouldn't be posted here but in another forum like comp.lang.c. |
|
 |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Sep 25, 2004 7:43 am |
|
|
The first is an example of the "ternary operator". Very confusing to many and you should limit its use. It means the same as
Code: |
if (a>b)
max = a;
else
max = b;
|
|
|
 |
|