Plain chars within structs?

6.6 Types

Moderators: misra-c, david ward

Post Reply
gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

Plain chars within structs?

Post by gs » Thu Mar 18, 2010 3:53 pm

The commentary for rule 6.1 and 6.2 states
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?

gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

Re: Plain chars within structs?

Post by gs » Wed Mar 24, 2010 5:02 pm

Or taking the address of a plain char object?

jbezem
Posts: 20
Joined: Mon Aug 01, 2005 8:24 pm
Company: JB Enterprises
Location: Germany
Contact:

Re: Plain chars within structs?

Post by jbezem » Thu Mar 25, 2010 6:39 am

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
Johan Bezem
Email: [email protected]
Tel: +49 172 5463210
Web: http://www.bezem.de/

gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

Re: Plain chars within structs?

Post by gs » Tue Apr 06, 2010 8:19 pm

Perhaps; however, the wording of the guidelines state:
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.

misra-c
Posts: 556
Joined: Thu Jan 05, 2006 1:11 pm

Re: Plain chars within structs?

Post by misra-c » Thu May 13, 2010 9:44 am

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

Post Reply

Return to “6.6 Types”