Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible inaccurate example?
#1
The following is the example reported for Rule 2.2 (dead code):

Quote:In this example, it is assumed that the object pointed to by p is used in other functions.

Code:
extern volatile uint16_t v;
extern char *p;

void f (void )  {
   uint16_t x;
   (void) v;  /* Compliant - v is accessed for its side effect * and the cast  to void is permitted by exception */
   (int32_t) v; /* Non-compliant - the cast operator is dead */
   v >> 3;     /* Non-compliant - the >> operator is dead */
   x = 3;      /* Non-compliant - the = operator is dead * - x is not subsequently read */
   *p++;       /* Non-compliant - result of * operator is not used */
   (*p)++;     /* Compliant - *p is incremented */
}

I'm not sure that last but one statement represents a non-compliance. In fact, the expression *p++ is treated as *(p++), as the precedence of postfix ++ is higher than *. Indeed the result of * operator is not used, but p value results permanently increased, and p is a global variable. How can be stated that it is not compliant, alias dead code, i.e. "...whose removal would not affect program behaviour"?
<t></t>


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)