 |
|
 |
RENESAS TOOL NEWS on September 1, 2004: RSO-M3T-NC308WA-040901D
A Note on Using C Compiler Packages M3T-NC308WA and M3T-NC30WA
--On Reading Members of Bit Fields in an Array--
|
Please take note of the following problem in using the M3T-NC308WA and
M3T-NC30WA C-compiler packages:
- On reading members of bit fields in an array
- Products and Versions Concerned
M3T-NC30WA V.5.00 Release 1 through V.5.30 Release 1
(used for the M16C/60, M16C/30, M16C/Tiny, M16C/20, M16C/10,
and R8C/Tiny series MCUs)
M3T-NC308WA V.5.00 Release 1 through V.5.20 Release 1
(used for the M32C/80 and M16C/80 series MCUs)
- Description
The values of members of bit fields in an array may be incorrectly read out.
- 2.1 Conditions
- This problem occurs if all the following conditions are satisfied:
| (1) | Any of the optimizing options -O1, -O2, -O3, -O4, -O5, -O, -OR, and -OS is selected at compilation. |
| (2) | A constant is assigned to a member of a bit field in an array. |
| (3) | The above member of the bit field is read out after the assignment in (2). |
| (4) | The subscript of the array is altered in between (2) and (3). |
- 2.2 Example
-------------------------------------------------------------------------
struct STRUCT1 {
unsigned int b0:1;
};
extern struct STRUCT1 s[10];
extern unsigned int i, dummy;
void func(void)
{
s[i].b0 = 0; /* Condition (2) */
i = 0; /* Condition (4) */
if (s[i].b0 == 1) { /* Condition (3) */
dummy++;
}
}
-------------------------------------------------------------------------
- Workaround
Place a dummy asm function immediately before reading out a member of a bit field.
-------------------------------------------------------------------------
struct STRUCT1 {
unsigned int b0:1;
};
extern struct STRUCT1 s[10];
extern unsigned int i, dummy;
void func(void)
{
s[i].b0 = 0;
i = 0;
asm(); /* Dummy asm function placed */
if (s[i].b0 == 1) {
dummy++;
}
}
-------------------------------------------------------------------------
- Schedule of Fixing the Problem
We plan to fix this problem in our next release of the products.
|
 |