Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 0-1-6 and Boolean variables
#9
This clarification of the rule seems to be contrary to the first example provided in spec.
Code:
int16_t critical (int16_t i, int16_t j)
{
    int16_t result = 0;
    int16_t k = ( 3 * i ) + ( j * j );
    
    // should k be checked here?
    if ( f2() )
    {
        // k will only be tested here if f2 returns true
        // Initialization of k could be moved here
        if ( k > 0 )
        {
            throw(42);
        }
    }
    // Non-compliant- value of k not used if f2 () returns false
    return result;
}
Is this also compliant because there is a path through the code where k is read?
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)