Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2.2 Dead code, 'operations' and casts
#1
Question 
Hi,

I have a question regarding the meaning of 'Dead Code' within MISRA-2012.  My question is, I believe, somewhat similar to this thread, but the contents of that thread appear to be missing such that I cannot determine what the exact question was, nor the answer.

My questions are:

1) What is an 'operation'?  'Dead code' is defined in terms of 'operations', but 'operation' is never defined in MISRA.

2) Does an addition/subtraction of a constant 0 to a value (either literally or by macro) count as dead code?  This sometimes happens in the context of register offsets where the first offset is 0.
Code:
#define BASE_ADDR 0x80000000u
#define CTRL_OFFSET 0x0u
uint32_t a = BASE_ADDR + 0x0u; // Dead addition?
uint32_t b = BASE_ADDR + CTRL_OFFSET; // Dead addition?

3) Does a cast of a value to it's own type count as dead code?
Code:
uint8_t a = (uint8_t)0u; // Dead cast? (Type of 0u is UTLR)
uint8_t b = (uint8_t)a; // Dead cast? (Type of a is uint8_t)


4) Does an explicit cast to a type for which implicit conversion is allowed count as dead code?
Code:
uint8_t a = (uint8_t)0; // Dead cast? (Type of 0 is STLR, but assignment is permitted by exception)
uint16_t b = (uint16_t)a; // Dead cast? (Conversion to wider type of same signedness is allowed implicitly)
Reply


Messages In This Thread
2.2 Dead code, 'operations' and casts - by ACHart - 21-10-2021, 01:39 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)