-->
Page 1 of 1

what does the means of operator "->" in C proramming for esp

PostPosted: Wed Feb 24, 2016 1:07 am
by saytinh
I saw many operator "->" in example but can not understand what does that operator mean. Anyone can help me to explain.

Here is an example having "->"
Code: Select allLOCAL uint32_t ICACHE_FLASH_ATTR
CMD_Exec(const CMD_LIST *scp, PACKET_CMD *packet)
{
   uint32_t ret;
   uint16_t crc = 0;
   while (scp->sc_name != CMD_NULL){
      if(scp->sc_name == packet->cmd) {
         ret = scp->sc_function(packet);
         if(packet->_return){
            INFO("CMD: Response return value: %d, cmd: %d\r\n", ret, packet->cmd);
            crc = CMD_ResponseStart(packet->cmd, 0, ret, 0);
            CMD_ResponseEnd(crc);
         }

         return ret;
      }
      scp++;
   }
   return 0;
}

Re: what does the means of operator "->" in C proramming for

PostPosted: Wed Feb 24, 2016 1:41 am
by lethe
It's a dereference for a struct/class member of a pointer.
If you have a struct "s" with a member "m", you would normally access "m" using "s.m".
If s however is a pointer to a struct, you have to dereference s first, before you can access m like this: "(*s).m". "s->m" is a shorthand for that.
See https://en.wikipedia.org/wiki/Struct_%2 ... _to_struct