implicitly cast - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: General Questions (https://forum.misra.org.uk/forumdisplay.php?fid=27) +--- Thread: implicitly cast (/showthread.php?tid=238) |
implicitly cast - warawut - 05-04-2006 According to source code below, please kindly help me to clear understanding whether where are the implicitly cast and they will cast to what type? Warning: Unsuffixed integral literal implicitly cast to another type. Source code struct { unsigned char multiple: 1; unsigned char event: 1; unsigned char checksum: 1; unsigned char conditional: 1; } flag; ... void transmit(void) { … if (flag.conditional == 1) { [color=red][b] Re: implicitly cast - Hammer - 06-04-2006 [quote="warawut"]... if (flag.conditional == 1) { [color=red][b] - Hammer - 06-04-2006 and by using unsigned char in a bit field you are also violating rule 6.4 Bug in tool - derek_farn - 06-04-2006 In C90 this code is making use of an extension (in C99 it is implementation-defined behavior; sentence 1385 http://c0x.coding-guidelines.com/6.7.2.1.html). I am guessing that the tool performing the check is not handling the semantics correctly. Even if unsigned char had the same size as unsigned int, the bit-field member would be promoted to type int (not unsigned int; sentence 669 http://c0x.coding-guidelines.com/6.3.1.1.html). I would complain to the tool vendor that they are incorrectly flagging this construct. |