CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Inquiry on C instruction shortcuts and Macro

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Inquiry on C instruction shortcuts and Macro
PostPosted: Fri Sep 24, 2004 9:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Sep 25, 2004 5:37 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Sat Sep 25, 2004 7:43 am     Reply with quote

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;
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group