if statement with structure member and rule 10.1 - 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: if statement with structure member and rule 10.1 (/showthread.php?tid=863) |
if statement with structure member and rule 10.1 - rhbarnes - 11-11-2011 I have a structure containing an unsigned int member; if I use any of the relational operators (>=, = u16_rev1_min) /* this violates rule 10.1 */ { // do something... } uint16_t u16_rev1_min, u16_tmp; u16_tmp = st_hardware_revs.u16_hw_rev1; if (u16_tmp >= u16_rev1_min) /* this does not violates rule 10.1 */ { // do something... } [/code] My initial thought was due to the underlying 'int' type of the relational operator, however if this is the case then why does the second piece of code pass? Am I missing some implicit conversion applied to the strucuture reference? Regards Re: if statement with structure member and rule 10.1 - misra-c - 15-11-2011 Rule 10.1 is concerned with underlying types of expressions but not with the form of those expressions. Therefore two expressions with an underlying type of unsigned int should be treated in the same manner regardless of whether, for example, one is an object (variable) and the other is a member of a structure. This would be something to discuss with the supplier of the checking tool as it seems to be diagnosing Rule 10.1 violations when it should not be doing so. |