Rule 5-0-12 - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19) +---- Forum: 6.5 Expressions (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=134) +---- Thread: Rule 5-0-12 (/showthread.php?tid=1273) |
Rule 5-0-12 - dg1980 - 15-09-2016 From the official text: Code: uint8_t b = '\r';//Non-compliant, explicitly unsigned Code: uint8_t b = static_cast('\r');//Compliant Re: Rule 5-0-12 - dg1980 - 26-09-2016 Ok, I just tested 2 different MISRA tools and both consider the following code to be compliant with 5-0-12: Code: uint8_t str[] = { As there seems to be a lot of interpretation going on among tool suppliers, i would suggest stripping down this rule to it´s bare essentials in the next version of MISRA C++: Quote:Don't rely on the signedness of plain char. Period. Code: extern char x; if (x == -1)//non-compliant as it is implementation defined whether char is signed or unsigned In fact, in some communication protocols you have to mix numeric information (e.g. frame length) with character data (e.g. special strings). How would you do that without deviating from 5-0-12 in it´s current form? Re: Rule 5-0-12 - misra cpp - 11-10-2016 You (and the tools) are correct, the use of static_cast makes the assignments compliant. The situation you cite, of the need to mix numeric and character data in communication protocols is a case where a deviation is justified |