Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 4-5-3 about using relational operators to determine uint8_t
#1
Quote:Exceptionally, the following operators may be used if the associated restriction is observed:
• The binary + operator may be used to add an integral value in the range 0 to 9 to ‘0’;
• The binary – operator may be used to subtract character '0'.
• The relational operators <, <=, >, >= may be used to determine if a character (or wide
character) represents a digit.
According to exceptions and cases of Rule 4-5-3, it seems that Exp1 apples to uint8_t and Exp2, Exp3 apply to character (wide character). And the rule title mainly cares about plain char and wchar_t, so, 
1. What about using uint8_t as operands of relational operators?
2. Which kind of cases does uint8_t violate this rule? Does this rule only check binary operator "+" only for uint8_t?
Code:
void f(void)
{
    char ch = 't';
    if (( ch >= '0') && ( ch <= '9')) // Compliant by exception
    {
        v = ch – '0';                 // Compliant by exception
    }

    unsigned char uc;
    if (( uc >= '0') && ( uc <= '9'))  // compliant or non-compliant?
    {
    }
}
Reply


Messages In This Thread
Rule 4-5-3 about using relational operators to determine uint8_t - by zhaohui - 08-12-2022, 08:00 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)