Posts: 581

Threads: 17

Joined: Jan 2006

Reputation:

**0**
Both of (a > 3) and (b > 5u) have int type according to the C standard and an effectively Boolean type for purposes of MISRA C as described in the Glossary.

There is no arithmetic type conversion taking place on the operands of the && operator. Depending on the definition of the types t_int8 and t_uint16, there may be promotion and/or balancing conversions taking place on the operands of the > operators but these have no effect on the type of their results.

It seems that the MISRA checker that you are using is not configured properly or is not performing the check correctly.

Posted by and on behalf of the MISRA C Working Group

Posts: 70

Threads: 8

Joined: Dec 2007

Reputation:

**0**
Is that really correct? If "int" on the particular system is 16 bits, then

a will be integer promoted to type int.

3 is of type int.

(a > 3) will be of type int.

b will remain unsigned int

5u will remain unsigned int

(b > 5u) will be of type unsigned int

(a > 3) && (b > 5u), the usual arithmetic conversions take place, converting the left-side expression to unsigned int.

<t></t>

Posts: 10

Threads: 1

Joined: Jun 2007

Reputation:

**0**
Yes, it is correct. The standard states that the relational operators yield a result of type int.

<t></t>

Posts: 70

Threads: 8

Joined: Dec 2007

Reputation:

**0**
ISO 9899:1999 6.5.8 Relational operators

"3 If both of the operands have arithmetic type, the usual arithmetic conversions are

performed."

ISO 9899:1999 6.3.1.8 Usual arithmetic conversions

... (rules for floats)

"Otherwise, the integer promotions are performed on both operands. Then the following rules are applied to the promoted operands:

If both operands have the same type, then no further conversion is needed.

Otherwise, if both operands have signed integer types or both have unsigned

integer types, the operand with the type of lesser integer conversion rank is

converted to the type of the operand with greater rank.

Otherwise, if the operand that has unsigned integer type has rank greater or

equal to the rank of the type of the other operand, then the operand with

signed integer type is converted to the type of the operand with unsigned

integer type.

Otherwise, if the type of the operand with signed integer type can represent

all of the values of the type of the operand with unsigned integer type, then

the operand with unsigned integer type is converted to the type of the

operand with signed integer type.

Otherwise, both operands are converted to the unsigned integer type

corresponding to the type of the operand with signed integer type."

If the above is different in C90, then please ignore my post. I suspect it is worded exactly the same, however.

<t></t>

Posts: 70

Threads: 8

Joined: Dec 2007

Reputation:

**0**
I just found that rule too. So either operand is guaranteed to be int, by this special rule for the relational operators. However, the operands are still subject to the usual arithmetic conversions for the sake of evaluating the operands, so there could be implicit conversions still, just not in this particular example.

<t></t>

Posts: 581

Threads: 17

Joined: Jan 2006

Reputation:

**0**
Yes, but see also C99 Section 6.3.8 paragraph 6 and Section 6.3.9 paragraph 3. These state that the results of relational and equality operators respectively have type int.

The type of the result is independent of the promotions and usual arithmetic conversions that may be performed on the operands of relational and equality operators.

Posted by and on behalf of the MISRA C Working Group