3 ms·
Specifying behavior is a bit more complex than that. There is a wide range of "unspecified" and the "full UB" one is the easiest from the spec point of view. Us
by obl 8y ago
Specifying behavior is a bit more complex than that. There is a wide range of "unspecified" and the "full UB" one is the easiest from the spec point of view. Using the shift example :
- allowed to assume that the negative shift does not happen (what it says now)
- the value of each dynamic negative shift is unspecified but it must have a well defined value, however the same shift operation in the source code could return a different output given the same inputs dynamically (eg in a different loop iteration or function call)
- each source code shift is a well defined (unspecified on negative inputs) function
- all shifts in the program are a well defined (unspecified) function
So, for example, the last (least surprising) version means that you have to compile every shift to the target CPU's shift and that you also have to use the target's behavior when you constant fold a shift at compile time.