07-04-2017, 08:45 AM
dg1980 Wrote:Maybe this extended and commented sample answers your question:
Code:int32_t main(void)
{
int32_t ret = 0;
int32_t state = 0;
nMISRA::C c(state);
*c.getB() = 1;// const member changing the state of the object, triggering error condition below
if (c.getState() != 0)
{
ret = -1;// error
}
return ret;
}
Well, `state` is not part of the object `c` (and likely not "class data"). It doesn't make much sense if this rule is to enforce that `getB` only return a const handler of `state`, because `state` is already in scope and could be modified without calling `getB`!
Code:
int32_t state = 0;
nMISRA::C c(state);
state = 1;
if (c.getState() != 0)
...
So I don't think the original example follows the rationale of the rule and thus the original question.
<t></t>