 |
|
 |
RENESAS TOOL NEWS on November 1, 2004: RSO-SQMlint-041101D
A Note on Using MISRA-C Rule Checker SQMlint
|
Please take note of the following problem in using the MISRA-C rule checker
SQMlint (This expands functions of Renesas-made C compilers):
- On using a typedef name as the operand of a sizeof operator
- Versions Concerned
SQMlint V.1.00 Release 1 and V.1.01 Release 00
- Description
Using a typedef name as the operand of a sizeof operator may cause a system error to arise.
- Conditions
This problem occurs if the following conditions are all satisfied:
| (1) | An incomplete type of structure is declared using typedef. |
| (2) | This structure is defined after its declaration in (1). |
| (3) | A typedef name is used as the operand of a sizeof operator. |
Example:
---------------------------------------------------------------------
typedef struct TAG typedef_name; /* Condition (1) */
struct TAG /* Condition (2) */
{
char member1;
};
void func(void)
{
int i = sizeof(typedef_name); /* Condition (3) */
}
---------------------------------------------------------------------
- Workaround
This problem can be circumvented in either of the following ways:
(1) First, define an incomplete type of structure, and then declare it
using typedef.
----------------------------------------------------------------
struct TAG
{
char member1;
};
typedef struct TAG typedef_name;
void func(void)
{
int i = sizeof(typedef_name);
}
----------------------------------------------------------------
(2) Use the structure tag in the typedef declaration as the operand of
a sizeof operator, instead of a typedef name.
----------------------------------------------------------------
typedef struct TAG typedef_name;
struct TAG
{
char member1;
};
void func(void)
{
int i = sizeof(struct TAG);
}
----------------------------------------------------------------
- Schedule of Fixing the Problem
We plan to fix this problem in our next release of the product.
|
 |