Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unclear why this code is not compliant with rule 11.3
#2
Hi

I'm not part of MISRA, I'm just hanging around waiting for an answer to my own questions, so don't take this as gospel, but...

your code example does not show how TaskParam_t and TaskConfig_t are defined, maybe they are different typedefs?

If one intended that two variables were the same type, presumably one would use the same typedef for both. Using a different typedef suggests that the implementation of one could change without changing the implementation of the other; so, they might currently be declared identically but they are different types.

This is a similar idea to the original Hungarian notation (not "systems Hungarian"!) where "the concept of "type" in this context is determined by the set of operations that can be applied to a quantity" ... "The point is that "integers" x and y are not of the same type if Position (x,y) is legal but Position (y,x) is nonsensical". (https://msdn.microsoft.com/en-us/library...60%29.aspx)

He's saying that even if x and y are both, say, uint16_t, they cannot be considered the same type if they cannot be used for the same thing.

Now, it would be a very clever static analyser that would detect such semantic use of a simple integer type; that's not going to happen. But if you use typedef, you are giving the analyser a very clear hint. If you have separate typedefs for TaskParam_t and TaskConfig_t, you must have wanted to use them for different purposes, so to define different types, even if today the implementations of the two types look similar.

Does that help?
<t></t>


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)