Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
It 8.12 intended to be so strict?
#1
Hello,

It is clear by looking at the title of rule 8.12 
Quote:Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique

That the following code is non-compliant:

Code:
// Non-compliant, yellow has an implixitly defined value that it shares with last
enum colour { red, blue, green, yellow, last = yellow };

This is a relatively common pattern, and the alternatives seem worse.

It is the intent of this rule to prevent this pattern, or is it just a result of the wording?
By the way, this code is compliant with the C++ version of this rule in MISRA C++:2023.
Reply
#2
The MISRA C rule 8.12 is an example of a simple deterministic rule, that traps circumstances that one might wish to permit.

The related MISRA C++:2023 rule 11.6.3 has an exception which appears to resolve the issue highlighted.

The MISRA C WG will consider adding the exception to a future update of MISRA C
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)