Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plain chars within structs?
#1
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?
Reply
#2
Or taking the address of a plain char object?
Reply
#3
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
<r>Johan Bezem<br/>
Email: <EMAIL email="[email protected]">[email protected]</EMAIL><br/>
Tel: +49 172 5463210<br/>
Web: <URL url="http://www.bezem.de/">http://www.bezem.de/</URL></r>
Reply
#4
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.
Reply
#5
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.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)