Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Does constness count as a type difference in rule 11.2?
#3
This response refers to code in the following form. It is assumed that X is a pointer as mentioned in the wording.
Code:
struct s_EthBuf;
typedef struct s_EthBuf *TEthBuf;
typedef const struct s_EthBuf *CTEthBuf;

extern void foo(CTEthBuf buf);

void fn ( struct s_EthBuf *X )
{
   CTEthBuf a = X;
   const TEthBuf b = X;
   TEthBuf c = X;

   foo(X);
}
Where pointers are involved, Rule 11.2 applies to the unqualified types that are pointed to by the pointer. Therefore none of these examples violate rule 11.2.

The destination pointer must contain all the type qualifications of the source type, otherwise the result is a constraint error in C99. See section 8.11 of the MISRA-C guidelines. There is no restriction on the destination having more type qualifiers than the source.
Posted by and on behalf of the MISRA C Working Group
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)