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 CCS Technical Support

-> operator

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



Joined: 05 Jul 2007
Posts: 18

View user's profile Send private message

-> operator
PostPosted: Wed Aug 22, 2007 3:05 pm     Reply with quote

Can anyone please give me a hint as what this operator (->) does...for example.

Code:

   if(cb->buf[0] == readDips())         // Valid Address
      {
         switch(cb->buf[1])               // Function
         {
            case 0x01:   // Read Coil Status
             {
               readCoils();                        // Read status of Coils
               
               break;
            }
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Aug 22, 2007 3:53 pm     Reply with quote

http://www.amazon.com/C-Programming-Language-2nd/dp/0131103628

The arrow notation is used when dereferencing a pointer to a structure. On function calling it is often more efficient to pass a pointer to a structure than passing (a copy of) the structure.

To dereference the structure you could write code like
Code:
(*cb).buf[1]
Note, the parentheses are necessary here because the . operator has higher precedence than the indirection operator, *. We must first dereference the pointer, and then select its appropriate member.

Since dereferencing structures like this is a common task they have defined a special pointer operator, called arrow, and the above code becomes:
Code:
cb->buf[1]
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