MISRA Discussion Forums
Plain chars within structs? - 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.6 Types (https://forum.misra.org.uk/forumdisplay.php?fid=33)
+---- Thread: Plain chars within structs? (/showthread.php?tid=720)



Plain chars within structs? - gs - 18-03-2010

The commentary for rule 6.1 and 6.2 states
Quote:The permissible operators on plain char types are the simple assignment operator (=), equality operators (==, !=) and explicit casts to integral types. Additionally, the second and third operands of the ternary conditional operator may both be of plain char type.
What about the '.' operator? Or the '->' operator? Could not an object of structure type contain a plain char member, making that member the second operand of the operator?

What about bit addressing or sizeof?


Re: Plain chars within structs? - gs - 24-03-2010

Or taking the address of a plain char object?


Re: Plain chars within structs? - jbezem - 25-03-2010

Using . or -> or & on a variable is IMHO not an operation on the _value_ of that variable (or struct member, so it's in a different category. Maybe the wording should be more clear that assignment and comparison (for instance) are operating on the values, the address operator is providing meta-information (the address, not the value), and . and -> are providing meta-information on the struct.

FWIW,

Johan


Re: Plain chars within structs? - gs - 06-04-2010

Perhaps; however, the wording of the guidelines state:
Quote:The permissible operators on plain char types are the simple assignment operator ...
(Emphasis added.) The guidelines do not appear to limit the restriction to values; hence, my confusion.


Re: Plain chars within structs? - misra-c - 13-05-2010

Neither '.' nor '->' operates on char type even though they may yield a result of char type. Therefore they are both permitted by Rules 6.1 and 6.2.

The supporting text restricts operations on char type to assignment, equality, conditional operations and certain type-casts. The sizeof and & operators should also have appeared in this list of permitted operations.