Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C Operators - Embedded C

  • 20-05-2006 08: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, Registered Users 2 Posts: 26,449 ✭✭✭✭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, Registered Users 2 Posts: 684 ✭✭✭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, Registered Users 2 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