Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 13.3 incr/decr op in initialization
#1
Based on the example in MISRA 2023 C this is non-compliant:
Code:
  int u8a=0;  // implied
  u8a = u8b++;  //don't accept assignment and increment on the same line

  but what about in initialization? According to PCLP tool it's acceptable:
Code:
  int u8a = u8b++;

My view is that de/increment shouldn't be mixed with anything and it should be alone in one line to avoid any chance of confusion.

Please clarify.
Reply
#2
The examples for Rule 13.3 state:
Code:
The expression:
u8a = u8b++
is non-compliant.

The glossary also clarifies that assignment includes Using an expression to initialize all or part of an object.

From this, the intent of Rule 13.3 (Advisory) is that use of ++ in an initialization is non-compliant.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)