MISRA Discussion Forums

Full Version: 10.1 in a macro
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,


i got something like this:

[code]
#define X_MASK 0xFU
#define FOO(_a) ((_a) % 10U)
#define BAR(_b) (1U
The expression resulting from the expansion of BAR(FOO(2U)) is a constant expression with the value 4 and type unsigned int. According to Section 6.10.4 of the MISRA C Guidelines, the underlying type of the expression is unsigned char, being the smallest unsigned type that can represent the value 4. Further, according the Section 6.10.5, constant expressions are not complex expressions.

Rule 10.1(a) will be broken if the type of the object REGACESSMAKRO is either smaller than unsigned char, or is a signed type. Similarly, Rule 10.1(a) will be broken if either of these is true for the type CAST_TO_REGISTER_SIZE. Since the types are not specified in the example, it is not possible to say for sure.

Rule 10.1(b) should never be broken in this example because the expression on the right-hand side of the assignment is not composite. This appears to be the part of the rule your checking tool identifies as being broken so it would seem that it is not performing the check correctly.

Note: the example code has some missing ) and a missing ; but it was clear where these should have been so their omission doesn't affect the answer given here.
Thank you for your detailed analyse. Sorry that the example contained some mistakes. But you helpd me with your answer and i fixed the error today.