 |
|
 |
MAEC TOOL NEWS:
MAECT-M3T-NC308WA-020301D
A Note on C Compilers M3T-NC308WA and M3T-NC30WA
|
Please take note of the following problem in using C compilers (with an assembler and integrated development environment) M3T-NC308WA and M3T-NC30WA.
- On switch-case statements
- Products and Versions Concerned
- For the M32C/80 and M16C/80 series MCUs:
- M3T-NC308WA V.1.00 Release 1 -- V.3.10 Release 3
- For the M16C/60, M16C/20, and M16C/10 series MCUs:
- M3T-NC30WA V.1.00 Release 1 -- V.5.00 Release 1
- Description
When compiling switch-case statements, code that makes a jump only to the default or a specific case label may be generated no matter what case value meets the conditional expression.
- Conditions
- This problem occurs if condition (1) or (2) below is satisfied.
- (1) In the conditional expression of a switch statement, a variable of type unsigned char is used, and the sequence of the case values is any of the following three types:
- a. The case values are 255 consecutive numbers from 1 to 255.
- b. The case values are 255 consecutive numbers from 0 to 254.
- c. The total number of cases (excluding the default) is 135 or more with the minimum case value 0 and the maximum 255.
- (2) In the conditional expression of a switch statement, a variable of type signed char is used, and the sequence of the case values is any of the following three types:
- a. The case values are 255 consecutive numbers from -127 to +127.
- b. The case values are 255 consecutive numbers from -128 to +126.
- c. The total number of cases (excluding the default) is 135 or more with the minimum case value -128 and the maximum 127.
- Example
In condition (1)-a:
--------------------------------------------------------------------
char c;
switch(c){
case 1:
case 2:
func(3);
break;
:
:
case 255:
func(255);
break;
default:
break;
}
--------------------------------------------------------------------
- Workaround
In the conditional expression of the switch statement, when the variable is of type unsigned char, cast it to an unisigned int value; when it is of type signed char, cast it to a signed int value.
[Example]
--------------------------------------------------------------------
char c;
switch((unsigned int)c){ /* Variable c of type unsigned char
case 1: is cast to of type unsigned int */
:
:
case 255:
:
}
--------------------------------------------------------------------
- Schedule of Fixing the Problem
We plan to fix this problem in our next release.
|
 |