MISRA Discussion Forums
10.1 in a macro - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.10 Arithmetic Type Conversions (https://forum.misra.org.uk/forumdisplay.php?fid=37)
+---- Thread: 10.1 in a macro (/showthread.php?tid=917)



10.1 in a macro - borth - 02-10-2012

Hello,


i got something like this:

[code]
#define X_MASK 0xFU
#define FOO(_a) ((_a) % 10U)
#define BAR(_b) (1U


Re: 10.1 in a macro - misra-c - 03-10-2012

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.


Re: 10.1 in a macro - borth - 04-10-2012

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.