Infinite loop language lawyering
Infinite loop language lawyering
Posted Jul 8, 2024 12:54 UTC (Mon) by khim (subscriber, #9252)In reply to: Infinite loop language lawyering by pizza
Parent article: New features in C++26
Result would be the same either way simply because such code doesn't contain any undefined behaviors.
Addition happens as int
s even if source is char
, and 400
fits in int
on all known compilers.
Conversion from int
into 8-bit quantity overflows, sure, but that's not an issue, that particular overflow if very well defined: the result is the unique value of the destination type that is congruent to the source integer modulo
2ᴺ
, where N
is the width of the destination type
Since there are no undefined behaviors and results are well-defined… compilers don't have a choice: language says the result would be -112
, there are no ambiguity.