This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Meaning of operator %=

Hello everybody,

I have seen the operator %= used in a code meant for Keil C. Can somebody explain me its purpose? Thanks.

www.8051projects.net/.../forum_viewtopic.php

char getchar()
   {
   volatile char c;

   while(RxInChar == RxOutChar);
   ES = 0;                         /* Disable Interrupts */
   c = RxBuffer[ RxOutChar++ ];
   RxOutChar %= BUF_SIZE;
   ES = 1;                         /* Enable Interrupts */

   return( c );
   }

Parents
  • Sorry but I don't think so.

    RxOutChar %= BUF_SIZE;
    

    From the code it seems that RxOutChar points to a location in receive buffer RxBuffer of size BUF_SIZE. So after incrementing RxOutChar if it exceeds BUF_SIZE it should become zero, otherwise no change.

    If I am correct, what is the exact meaning of %= . What mathematical/logical operation it does?

Reply
  • Sorry but I don't think so.

    RxOutChar %= BUF_SIZE;
    

    From the code it seems that RxOutChar points to a location in receive buffer RxBuffer of size BUF_SIZE. So after incrementing RxOutChar if it exceeds BUF_SIZE it should become zero, otherwise no change.

    If I am correct, what is the exact meaning of %= . What mathematical/logical operation it does?

Children
No data