I’ve a theoretical question about these two statements:
Assuming p a pointer to an Integer and a an Integer:
a) if(p==a){.....} or if(p>a)..
b) p=a;
All of them are illegal and b is especially dangerous but how does standard C consider them?
Reading the standard, I haven’t found if they are errors, undefined behaviors, unspecified behavior, constraint violation, if one of them is legal or other.
Looking in the countless similar question, I haven’t found a solution.
C11 (n1570) §6.5.8 [Relational operators] / 2:
(real type means the integer types, enums, real floating point types and
char(§6.2.5/17))§6.5.9 [Equality operators]
§6.5.16.1 [Simple assignment] / 1:
Basically, all 3 expressions violated the constraints set in the expression.
What does violating constraints mean? Errors? But nowhere says that violation of constraints shall cause the translation to fail. The C standard doesn’t seem to be very clear, but the closest interpretation would be:
§4 [Conformance] / 2:
but this talks about outside of constraints; and §5.1.1.3 [Diagnostics] / 1:
so the compiler needs to at least produce a message (as we can see in gcc), but did not say what they should do after that.
The example after this paragraph mentions that
and §6.7 [Declarations] / 3 does not explicitly mention that violating the Constraint will cause undefined behavior.
Therefore, I deduce that your 3 expressions are all undefined behaviors, accompanied with diagnostic messages.