 |
|
 |
RENESAS TOOL NEWS on May 16, 2005: RSO-M3T-NC30WA_2-050516D
A Note on Using the M3T-NC30WA C-Compiler Package
--On an Arithmetic Operation between Two unsigned-Type
Variables in a Controlling Expression-- |
Please take note of the following problem in using the M3T-NC30WA C-compiler package:
- On an arithmetic operation between two unsigned-type variables in a controlling expression
- Versions Concerned
M3T-NC30WA V.5.00 Release 1 through V.5.30 Release 02
(This C compiler package is used for the M16C/60, M16C/30, M16C/20, M16C/10,
M16C/Tiny, and R8C/Tiny series of MCUs.)
- Description
If the result of an arithmetic operation between two unsigned-type variables is compared with zero in the controlling expression of an controlling statement (if, while, do, etc.),
incorrect code may be generated.
- 2.1 Conditions
- This problem occurs if the following conditions are all satisfied:
| (1) |
An arithmetic operation between two unsigned-type variables is
performed in the controlling expression of a controlling statement
(any of the selection, iteration, and jump statements).
Here the combinations of unsigned-type variables are as
follows:
- two variables of type unsigned int
- two variables of type unsigned char
- a variable of type unsigned int and that of type unsigned char |
| (2) | The result of the operation in (1) itself is compared with zero. |
| (3) |
The comparison in (2) is made using the > or <= relational operator. |
| |
|
- 2.2 Example
-
---------------------------------------------------------------
unsigned int a,b;
if(a-b > 0)
i = 1;
else
i = -1;
---------------------------------------------------------------
- Workaround
Compare the result of the operation with zero as follows:
| (1) | If the > relational operator used, replace it with !=.
Example:
---------------------------------------------------------------
unsigned int a,b;
if( (a - b) != 0)
i = 1;
else
i = -1;
---------------------------------------------------------------
|
| (2) | If the <= relational operator used, replace it with ==.
Example:
---------------------------------------------------------------
unsigned int a,b;
if( (a - b) == 0)
i = 1;
else
i = -1;
---------------------------------------------------------------
|
- Schedule of Fixing the Problem
We plan to fix this problem in the next release of the product.
|
 |