Information about the left shift operator in the draft C99 standard (ISO / IEC9899: TC3, aka WG14 / N1256) is rather scarce.
Section 6.5.7 (bitwise shift operators) has already been specified by Alter Mann.
Appendix J, Section J.2 (Undefined Behavior) says the following:
Undefined behavior in the following cases:
[...]
- the expression is shifted by a negative number or by an amount greater than or equal to the width of the promoted expression (6.5.7).
- an expression having a signed advanced type is shifted to the left and either the value of the expression is negative or the result of the offset will not be presented in (6.5.7).
I do not think that the implementation is allowed for some mandatory undefined behavior. If I am not mistaken, the implementation is allowed to define unspecified behavior (but this is optional) and it is required to specify the behavior defined during the implementation , but undefined cannot be specified. This does not mean that the implementation cannot choose reasonable, meaningful behavior, but it cannot allow the user to rely on it (he cannot “indicate it”).
I admit that I’m not quite sure about this. Hope this helps.
Edit: With further reflection, I think that the corresponding implementation can determine the behavior that the standard considers undefined behavior , but the resulting program cannot be called appropriate (see section 3.4.3).
source share