MISRA Discussion Forums

Full Version: Plain chars within structs?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
Or taking the address of a plain char object?
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
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.
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.