Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Violation of Rule 11.4 or Rule 11.5?
#3
My reading of the C standard is that int* and const int* are two unqualified, different object types.
Hence, if Rule 11.4 is to be taken literally, converting a const int** to a int** is a violation.
Actually, even when converting the other way round, from int** to const int**,
i.e., when adding an inner-level qualifier, we should have a violation of Rule 11.4.

My question is how far should we go when considering Rule 11.5: is this rule meant to overlap with 11.4 or not?

Suppose that the quality control process requires the programmer to raise a formal deviation for each violation of a rule,
no matter if it is a mandatory or an advisory rule.
Consider my second example above, with the cast between different structure types.
Is it enough to raise a formal deviation for Rule 11.4, or should the programmer also raise a formal deviation for Rule 11.5?

Consider the following minor variant:
Code:
struct S { const int* i; };
struct T { float* f; };
struct S* ps;
struct T* pt = (struct T*) ps;
Again, is this a violation of just 11.4, or is it also violating 11.5?

Trickier examples can be proposed where the two structure types have differently qualified fields
that are not perfectly overlapping. For instance,
Code:
struct S { const int i; const int j; };
struct T { int i; char a; const char b; char c; const char d; };
struct S* ps;
struct T* pt = (struct T*) ps;

Thanks,
Enea.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)