 |
|
 |
MESC TOOL NEWS:
MESCT-CC32R-000916D
Please take note of the following problem in using cross-tool kit CC32R for the M32R family of MCUs.
- On defining structures containing bit fields of type char and the expressions for initializing them
- Versions Concerned
CC32R V.1.00 Release 1 -- V.2.10 Release 1
- Problem
- Defining structures containing bit fields of type char and the expressions for initializing them results in an internal error being displayed as shown below.
- cg32r: "file name", line number: internal error: illegal IL,
- size of initializer is larger than name size.
- 2.1 Conditions
This problem occurs if the following three conditions are satisfied:
- (1) A structure contains only more than one member of a bit field of type char or unsigned char.
- (2) The memory usage of the structure is an integer multiple of 4 bytes minus 1 (for example, 3, 7, 11 bytes, and so on) in total.
- (3) The above bit field is initialized immediately after defined.
- 2.2 Examples
- Example 1:
-----------------------------------------------------------------------------
struct S1 { /* Condition (1); All the members are
of type char or unsigned char */
unsigned char a:5; /* a: 1 byte */
unsigned char b:8; /* b: 1 byte */
char c:3; /* c: 1 byte */
} s1 /* Condition (2) The total of memory usage is 3 bytes */
= {0, 1, 2}; /* Condition (3) Initialized immediately after defined */
-----------------------------------------------------------------------------
- Example 2:
------------------------------------------------------------------------------
struct S2 { /* Condition (1); All the members are
of type char or unsigned char */
char a:5; /* a and b: 1 byte each */
char b:3;
char c:8; /* c: 1 byte */
char d:3; /* d and e: 1 byte each */
char e:4;
char f:6; /* f: 1 byte */
char g:5; /* g: 1 byte */
char h:6; /* h: 1 byte */
unsigned char i:4; /* i and j: 1 byte each */
unsigned char j:4;
} s2 /* Condition (2) The total of memory usage is 7 bytes */
= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
/* Condition (3) Initialized immediately after defined */
------------------------------------------------------------------------------
- Workaround
This problem will be circumvented by either of the following ways:
(1) Add a dummy member to the bit field to change the memory usage to an integer multiple of 4 bytes; then, condition (2) is sidestepped.
Modification of Example 1:
-----------------------------------------------------------------------------
struct S1 {
unsigned char a:5;
unsigned char b:8;
char c:3;
char dummy:8; /* Add 1 byte to change the total size to 4 bytes */
} s1
= {0, 1, 2};
------------------------------------------------------------------------------
(2) Omit a part of the initializing expression; then, condition (3) is sidestepped.
Modification of Example 2:
----------------------------------------------------------------------------------
struct S2 {
char a:5;
char b:3;
char c:8;
char d:3;
char e:4;
char f:6;
char g:5;
char h:6;
unsigned char i:4; /* i and j: 1 byte each */
unsigned char j:4;
} s2
= {0, 1, 2, 3, 4, 5, 6, 7}; /* Initialization of the last member is omitted */
-----------------------------------------------------------------------------------
Note: Dynamically initialize the bit field member, if necessary,
initialization of which was omitted immediately after its definition.
------------------------------------------------------------------------------
init_s2()
{
s2.i = 8; /* Initialize the last member
whose initialization was omitted */
s2.j = 9;
}
------------------------------------------------------------------------------
- Schedule of Fixing Problem
We plan to fix this problem in our next release.
|
 |