Page 47 - Programming Microcontrollers in C
P. 47

32     Chapter 1  Introduction to C

                              Often somebody will wonder what will happen if you have mul­
                          tiple increments, either pre or post, of a variable within a single
                          expression. There is an easy answer for that question. Do not do it.
                          The standard provides that between sequence points, an object shall
                          have its value modified at most once and the prior value of the object
                          shall be accessed only to determine its value. Interpretations of the
                          above requirements disallow statements such as
                   j = j++;

                          or

                   a[j] = j++;
                          or
                   m = j++ + ++j;


            Assignment Operators
                              Another shorthand that was included in C is called the assign­
                          ment operator. When you are programming, you will find that
                          expressions such as
                   i = i+2;

                          or

                   x = x<<1;
                          are used often. Almost any binary operator can be found on the right
                          side of the expression. A special set of operators was created in C to
                          simplify these expressions. The first expression can be written
                   i += 2;

                          and the second
                   x <<= 1;

                          These expressions use what is defined as an assignment operator.
                          The operators that can be used in assignment operators are

                              +      >>
                              -      <<
                              *      &
   42   43   44   45   46   47   48   49   50   51   52