Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C Operators - Embedded C

Options
  • 20-05-2006 8:32pm
    #1
    Closed Accounts Posts: 8


    Can any one tell me what -> means when used in embedded c? I think its a pointer but i am not altogether sure. Please tell me and put my mind at rest.....


Comments

  • Registered Users Posts: 26,578 ✭✭✭✭Creamy Goodness


    guitarmano wrote:
    Can any one tell me what -> means when used in embedded c? I think its a pointer but i am not altogether sure. Please tell me and put my mind at rest.....

    i'm pretty sure it's used for pointers to structures.

    have you any code so that others can confirm?


  • Registered Users Posts: 683 ✭✭✭Gosh


    The . and -> operators reference individual elements in structures and unions.

    The . operator is used when working with the actual structure or union, e.g.:
    employee.wage = 500.00;

    The -> is used when working with a pointer to the structure or union, e.g.:
    emp_ptr->wage = 500.00;


  • Registered Users Posts: 2,082 ✭✭✭Tobias Greeshman


    1. Use the . operator when referencing items in a structure when you have a direct reference to the structure.
    2. Use the -> operator when referencing items in a structure when you have an indirect reference to the structure (ie. a pointer to a structure).
    struct person
      {
         char *str_name ;
         char *str_address ;
         int age ;
      } ;
    
      ....
      person curr_person ;
      curr_person.str_name = new char [100 ] ;
      memset (curr_person.str_name, "John" ) ;
      ...
    
      person *ptr_person = new person ;
      ptr_person->age = 25 ;
      ptr_person->str_name = new char [ 100 ] ;
      memset ( ptr_person->str_name, "Peter" ) ;
     
      ...
    


Advertisement