Mikroelektronika MIKROE-738 Datenbogen

Seite von 682
248
mikoC PRO for PIC32
MikroElektronika
Expressions
Expression is a sequence of operators, operands, and punctuators that specifies a computation. Formally, expressions 
are defined recursively: subexpressions can be nested without formal limit. However, the compiler will report an out-of-
memory error if it can’t compile an expression that is too complex.
In ANSI C, the primary expressions are: constant (also referred to as literal), identifier, and (
expression
), defined 
recursively.
Expressions  are  evaluated  according  to  a  certain  conversion,  grouping,  associativity  and  precedence  rules,  which 
depends  on  the  operators  used,  presence  of  parentheses  and  data  types  of  the  operands.  The  precedence  and 
associativity  of  the  operators  are  summarized  in  Operator  Precedence  and  Associativity.  The  way  operands  and 
subexpressions are grouped does not necessarily specify the actual order in which they are evaluated by the mikroC 
PRO for PIC32.
Expressions can produce lvalue, rvalue, or no value. Expressions might cause side effects whether they produce a 
value or not.
Comma Expressions
One of the specifics of C is that it allows using of comma as a sequence operator to form so-called comma expressions 
or sequences. Comma expression is a comma-delimited list of expressions – it is formally treated as a single expression 
so it can be used in places where an expression is expected. The following sequence:
expression_1, expression_2;
results in the left-to-right evaluation of each 
expression
, with the value and type of 
expression_2
 giving the result 
of the whole expression. Result of 
expression_1
 is discarded.
Binary operator comma (
,
) has the lowest precedence and associates from left to right, so that 
a, b, c
 is the same 
as 
(a, b), c
. This allows writing sequences with any number of expressions:
expression_1, expression_2, ... expression_n;
which results in the left-to-right evaluation of each 
expression
, with the value and type of 
expression_n
 giving the 
result of the whole expression. Results of other 
expressions
 are discarded, but their (possible) side-effect do occur.
For example:
result = ( a = 5, b /= 2, c++ );
/* returns preincremented value of variable c,
   but also intializes a, divides b by 2 and increments c */
result = ( x = 10, y = x + 3, x--, z -= x * 3 - --y );
/* returns computed value of variable z,
   and also computes x and y */